? PQRSTUVWXYZ[\]^_ `abcdefghijklmno pqrstuvwxyz{|}~DEL"> ? PQRSTUVWXYZ[\]^_ `abcdefghijklmno pqrstuvwxyz{|}~DEL">

Presentation is loading. Please wait.

Presentation is loading. Please wait.

Manipulating Strings. What is a string? Data composed of text characters. The data is stored in consecutive bytes of memory. Each byte stores the ASCII.

Similar presentations


Presentation on theme: "Manipulating Strings. What is a string? Data composed of text characters. The data is stored in consecutive bytes of memory. Each byte stores the ASCII."— Presentation transcript:

1 Manipulating Strings

2 What is a string? Data composed of text characters. The data is stored in consecutive bytes of memory. Each byte stores the ASCII code for a single character.

3 The ASCII Character Set Hex0123456789ABCDEF Binary 0000000100100011010001010110011110001001101010111100110111101111 0 0000 BSHTLF CR 1 0001 ESC 2 0010 !"#$%&'()*+,-./ 3 0011 0123456789:;<=>? 4 0100 @ABCDEFGHIJKLMNO 5 0101 PQRSTUVWXYZ[\]^_ 6 0110 `abcdefghijklmno 7 0111 pqrstuvwxyz{|}~DEL

4 Storing a String When a String type variable is declared in VB6, 256 consecutive bytes of memory are reserved. The ASCII code for the fist character is stored in the first byte reserved. The code for the next character in the string is stored in the next byte.

5 Storing a String If the statement Dim name As String reserves 256 bytes starting at 1000(Hex), then Name = “Lew” Places the ASCII code for ‘L’ in 1000, and the code for ‘e’ in 1001…

6 Storing a String The ASCII table provides the codes: L – 01001100 e – 01100101 w – 01110111

7 Storing a String Memory locationContent 00010000 0000000001001100 00010000 0000000101100101 00010000 0000001001110111 00010000 0000001100000000 00010000 00000100Random junk 00010000 00000101″ … 00010000 00001111

8 How are strings manipulated? Program design requirements can pose a number of problems that can be solved by string manipulation. Chapter 5 of the “Programming for Literacy” illustrates several examples.

9 Inspection Functions Function NameReturn typeDescription Len (String1)LongReturns a Long, the number of characters in String1 InStr ([Start (Integer),] String1, String2) LongReturns a Long specifying the position of the first occurrence of String2 in String1, starting at Start if the argument is specified, otherwise at the beginning of String1 InStrRev (String1, String2, [Start (Integer])) LongReturns a Long specifying the position of the first occurrence of String2 in String1, from the end of String1 (or from Start if the argument is specified StrComp (String1, String2)IntegerReturns an integer indicating the comparison of String1 and String2, namely -1, 0 or +1 depending if String1 is less than, equal to, or greater than String2

10 Conversion Functions Function NameReturn typeDescription Asc (String)IntegerReturns an Integer, being the character code for the first character in the string Chr (Long)StringReturns the character corresponding to the specified code Str (Long)StringReturns a string representation of the number LCase (String1)StringReturns String1 converted to lower case UCase (String1)StringReturns String1 converted to UPPER case

11 SubString Functions Function NameReturn typeDescription Left (String1, Integer)StringReturns a string containing the specified number of characters from the left of String1 Ltrim (String1)StringReturns a string with blanks removed from the left of String1 Right (String1, Integer)StringReturns a string containing the specified number of characters from the right of String1 Rtrim (String1)StringReturns a string with blanks removed from the right of String1 Mid (String1, Start (Long), [Length (Long)]) StringReturns all (or Length if it is specified) characters from String1 starting at position Start

12 String Creation Functions Function NameReturn typeDescription Space (Long)StringReturns a string composed of blanks, as many as specified by Long String (Long, String1)StringReturns a string composed of the first character of String1, repeated as many times as specified by Long StrReverse (String1)StringReturns a string composed of the characters from String1 but in reverse order Replace (String1, String2, String3, [Start (Long)], [Count]) StringReturns a string with String2 replaced by String3, where ever it is found in String1, beginning at position Start, or replaces it Count times from position Start


Download ppt "Manipulating Strings. What is a string? Data composed of text characters. The data is stored in consecutive bytes of memory. Each byte stores the ASCII."

Similar presentations


Ads by Google