String Demonstrations

String Methods


Our variable x = Space

Our variable y = Space, the final frontier



Javascript Method Trying Results In
length x.length
y.length
5
25
Slice x.slice(0,3)
y.slice(-10,-5)
x.slice(1)
y.slice(-4)
Spa
l fro
pace
tier
Upper x.toUpperCase
y.toUpperCase
SPACE
SPACE, THE FINAL FRONTIER
Lower x.toLowerCase
y.toLowerCase
space
space, the final frontier
Concat y.concat(". These are the voyages of the Starship Enterprise..." Space, the final frontier. These are the voyages of the Starship Enterprise...
charAt x.charAt(3)
y.charAt(9)
c
e
charCodeAt
(return Unicode of character)
x.charCodeAt(3)
y.charCodeAt(9)
99
101
Substring x.substring(2,4) (start,end)
y.substring(2,7)
ac
ace,
Substr x.substr(1,2) (start,length)
y.substr(1,4)
pa
pace
Trim x.trim() Space


Find Replace


Sleeping in his car was never the plan but sometimes things don't work out as planned. This had been his life for the last three months and he was just beginning to get used to it. He didn't actually enjoy it, but he had accepted it and come to terms with it. Or at least he thought he had. All that changed when he put the key into the ignition, turned it and the engine didn't make a sound. The song came from the bathroom belting over the sound of the shower's running water. It was the same way each day began since he could remember. It listened intently and concluded that the singing today was as terrible as it had ever been. What if dogs were racist? Would they care about fur color….. “son, only play with other tan dogs”? Or maybe it would depend on breed, “honey, only play with other German Shepards, never poodles”. Better yet it could depend on occupation. “I’m a sled dog while you’re only a running companion, leave me alone”. Maybe the neighborhood they live in could be the way they choose which dogs to associate with and which to shun? Size could be the determining factor, “see how tall that dog is, they are probably dumb”. Luckily dogs don’t discriminate. Just watch at a dog park. Big black and white dogs wag their tails and play with tiny tan dogs. A service dog chases after the same ball as the off-duty police dog. So if dogs don’t discriminate then why do we?