Download presentation
Presentation is loading. Please wait.
1
What We Want To Do User enters: Mary Smith
We want to respond: Hi Mary! We know how to concatenate. How do we take part of a string?
2
Think of Scrabble tiles Each tile is a
Strings Think of Scrabble tiles Each tile is a Letter Number Punctuation mark Space (blank)
3
A literal string must be inside double quotes or single quotes
What is a String? A literal string must be inside double quotes or single quotes “this is a string” and this is not a string. Remember not to cut and paste
4
Concatenating (formally)
It means combining two or more things into one thing + Anything can be concatenated “awe” + “some” = “awesome” Whitespace only matters inside quotes “a”+“b” same as “a” = “b” “a ” + “b” NOT the same as “a” + “b”
5
Substring A substring is also a String
A substring is a part of another string “cake” is a substring of “birthday cake” so are “day”, “thd”, and “y cake” “they” is not, neither is “hello” or “dude” Will come back to how to extract substrings
6
Referencing characters
Each character has a position Note that it starts at 0, not 1 H I M O 1 2 3 4 5
7
JavaScripts Strings Length: stringname.length
Functions: stringname.function() Concatenation: + or stringname.concat() Lots more functions Use of negative index to come from end Built-in regular expressions Excellent summary
8
Useful Functions charAt() Character at the position indexOf()
Position of the first found occurrence lastIndexOf() Position of the last found occurrence replace() Replaces the matched substring with a new substring search() Position of the match substr() Substring from start position for number of chars substring() Substring from position 1 to position 2 toLowerCase() Converts a string to lowercase letters toUpperCase() Converts a string to uppercase letters trim() Removes whitespace from both ends of a string
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.