Notes
Outline
COM1100
Fundamentals of Computer Science –Winter 2000
Lecture 13
02/08/00
Lecture today
string
string
A string is any sequence of characters enclosed in double quotes.
Examples:
“This is a string”
“Hello, World !”
“*-“
“xyz 123 *!#@&”
How string stored?
A string is stored as an array of characters terminated by special end-of-string symbolic constant named NULL.
 The value assigned to the NULL constant is the escape sequence \0 and is the sentinel that marks the end of every string.
How string stored?
“Good Morning! “  is stored in memory like:
The string uses 14 storage locations, with the last character in the string being the end-of-string marker \0.
The double quotes are stored as part of the string.
But the actual size of this string is normally referred as 13.
From IOTools:
ChangeCase(string-variable, LowerCase)
Changes all the letters in string-variable to lower case.
ChangeCase(string-variable, UpperCase)
Changes all the letters in string-variable to lower case.
ChangeCase(string-variable, MixedCase)
Capitalize the first letter in every word and convert the rest of each word to lower case.
SquashString(string-variable)
Removes leading and trailing blanks from the string-variable
Examples
string s;
s = "good, morning !";
ChangeCase(s, UpperCase);
cout << s << endl;
ChangeCase(s, LowerCase);
cout << s << endl;
ChangeCase(s, MixedCase);
cout << s << endl;
Examples
string s;
s = "  Good, Morning !   ";
cout << s << endl;
SquashString(s);
cout << s << endl;
From the string class:
If s if of type string:
 s.length()
Find out the actual length of the string s
s.substr(pos, num)
Get the substring of s consisting of num characters starting at position pos
s[pos]
Get the character at position pos in s
 s1 == s2
Return true if and only if the two strings are equal
Example
Question: print out “Good Morning !” in the following format:
G
o
o
d
M
o
r
n
I
n
g
!