manipulating strings. what is a string? data composed of text characters. the data is stored in...

8
Manipulating Strings

Upload: cynthia-charles

Post on 23-Dec-2015

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 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

Manipulating Strings

Page 2: 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

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.

Page 3: 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

The 7-bit ASCII Character Set

Page 4: 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

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.

Page 5: 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

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…

Page 6: 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

Storing a String

The ASCII table provides the codes:

L – 01001100

e – 01100101

w – 01110111

Page 7: 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

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

Page 8: 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

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.