how do you represent a number with no value? mathematicians defined the “number” 0 (zero) how...
Post on 19-Jan-2016
214 Views
Preview:
TRANSCRIPT
PROGRAMMINGPART IV
USNA SI110
Programming Part IV 2
The Empty String
How do you represent a number with no value? Mathematicians defined the “number” 0 (zero)
How do we represent a string with no value? Use an empty string
What is an empty string? String of length zero Defined as “”
Open and close quote with no characters between Often used to initialize a string variable that will
be used later
Programming Part IV 3
Manipulating ASCII Values
Two string-related functions for dealing with ASCII values .charCodeAt(i)
Returns the ASCII value for the character at index i Returns the ASCII value as a Number (decimal)
“abcd”.charCodeAt(2) → 99 (ASCII value for “c”) String.fromCharCode(i)
Returns a single-character string Character is the ASCII character at code i
Character code can be in decimal or hex String.fromCharCode(99) → “c” String.fromCharCode(0x63) → “c”
(99 = 0x63)
Programming Part IV 4
Examples
Random password generator Lowercase conversion
top related