First Steps |
|
New names for old things |
So that's numbers... but what about letters? Words? Text?
The word we use for groups of characters is string. Here are some strings:
Ruby lets you do several nifty things with strings.
Here is a good way to remember this: '"hi " * 3' is the same as '"hi " + "hi " + "hi "' so it gives me "hi hi hi ".
Notice what happens if I forget the space in "hi ":
Now see what happens here:
When Ruby sees "1" it sees a string, not a number.
Here are some more nifty things you can do with text:
What do you expect these will do?:
"hello".length + "world".length "".empty? "Zoo".include? "oo" "cute".chop |
Try them!
Spell your name backwards.
What might "Daniel".reverse.reverse produce?
Spell your name backwards, make it lowercase, and capitalize the
first letter.
Try it with family members' names, the neighbor's dog, etc.
What do you think happens if you don't make the name lowercase first? (in the above exercise). Try it.
What is special about this phrase: "A man a plan a canal Panama"?
A palindrome is a word or phrase that looks the same if
you write it backwards. Here are some palindromes:
Play around with strings for a bit.
First Steps |
|
New names for old things |