1 / 17

Strings

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

nhi
Download Presentation

Strings

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Strings VB12 VB13

  2. 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

  3. 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

  4. 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

  5. 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

  6. Strings can be compared If strA = strB then … If strA < strB then … If strA >= strB then … VB13

  7. Strings can be joined together strFullName = strForeName & “ ” & strSurname de Mann Dan de Mann Dan Dan de Mann VB13

  8. 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

  9. 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

  10. 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

  11. 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

  12. 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

  13. UCase ( str ) returns the string str in uppercase Here’s one I made earlier UCase ( “Dan de Mann”) is “DAN DE MANN” VB13

  14. LCase ( str ) returns the string str in lowercase LCase ( “Dan de Mann”) is “dan de mann” VB13

  15. StrReverse ( str ) returns the string str backwards StrReverse ( “Dan de Mann”) is “nnaM ed naD” VB13

  16. Str ( sng ) converts a number to a string Str (75.2) is “75.2” Str (9561) is “9561” VB13

  17. 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

More Related