170 likes | 328 Views
Strings. VB12. Computers store characters internally as numbers. Each character has a corresponding number This number is called the ASCII code American Standard Code for Information Interchange. Asc ( ). Asc (x) evaluates to the ASCII value of the leftmost character of string x
E N D
Strings VB12 VB13
Computers store characters internally as numbers • Each character has a corresponding number • This number is called the ASCII code • American Standard Code for Information Interchange VB13
Asc ( ) • Asc (x) evaluates to the ASCII value of the leftmost character of string x • Asc (“A”) is 65 • Asc (“Bertie”) is 66 “D” Asc 68 VB13
Chr ( ) • Chr (y) evaluates to the character that has the ASCII value y • Chr (38) is “&” • Chr (32) is “ “ • Chr (40) is “(“ • Chr (65) is “A” • Chr (66) is “B” • Chr (97) is “a” • Chr (98) is “b” 97 Chr “a” VB13
Len ( str ) returns the number if characters in the string str • Len (“abc”) is 3 • Len (“qwerty”) is 6 • strName = “Dan de Mann” • Len (strName) is what? VB13
Strings can be compared If strA = strB then … If strA < strB then … If strA >= strB then … VB13
Strings can be joined together strFullName = strForeName & “ ” & strSurname de Mann Dan de Mann Dan Dan de Mann VB13
Len ( str ) returns the number if characters in the string str • Len (“abc”) is 3 • Len (“qwerty”) is 6 • strName = “Dan de Mann” • Len (strName) is 11 VB13
Left (str, int) returns a string with the int leftmost characters of string str • strName = “Dan de Mann” • Left ( strName, 5) is “Dan d” Dande Mann VB13
Right (str, int) returns a string with the int rightmost characters of string str • strName = “Dan de Mann” • Right ( strName, 5) is “ Mann” Dan de Mann VB13
Mid (str, intStart, intLen) returns a string with int chartacters from str, starting with the character at position intStart • strName = “Dan de Mann” • Mid ( strName, 5, 4) is “de M” Dan de Mann VB13
Convert lowercase to uppercase • Convert strX so that it is all in UPPERCASE strNewX = “” For N = 1 to Len (strX) strChar = Mid (strX, N, 1) If strChar >= “a” AND strChar <= “z” then strNewX = strNewX + chr (asc (strChar) – 32) Else strNewX = strNewX + strChar End if Next N VB13
UCase ( str ) returns the string str in uppercase Here’s one I made earlier UCase ( “Dan de Mann”) is “DAN DE MANN” VB13
LCase ( str ) returns the string str in lowercase LCase ( “Dan de Mann”) is “dan de mann” VB13
StrReverse ( str ) returns the string str backwards StrReverse ( “Dan de Mann”) is “nnaM ed naD” VB13
Str ( sng ) converts a number to a string Str (75.2) is “75.2” Str (9561) is “9561” VB13
Chr (int) Asc (str) Len (str) Left (str, int) Right (str, int) Mid (str, intStart, intLen) UCase (str) LCase (str) StrReverse (str) Str (num) String Functions - recap VB13