manipulating strings. what is a string? data composed of text characters. the data is stored in...
TRANSCRIPT
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 code for a single character.
The 7-bit ASCII Character Set
Storing a String
When a String type variable is declared, VB reserves 256 consecutive bytes of memory.
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.
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…
Storing a String
The ASCII table provides the codes:
L – 01001100
e – 01100101
w – 01110111
Storing a String
Memory location Content
00010000 00000000 01001100
00010000 00000001 01100101
00010000 00000010 01110111
00010000 00000011 00000000
00010000 00000100 Random junk
00010000 00000101 ″
…
00010000 00001111
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.
Let’s look at Ex5-4.