Strings
So that's numbers... but what about letters? Words? Text?
The word we use for groups of letters is string.
Here are some strings:
- "Hello."
- "Ruby rocks."
- "5 is my favorite number... what's yours?"
- "Snoopy says #%^?&*@!"
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 this will do:
>> 'hello'.length + 'world'.length
Try it.
- Play around with strings for a bit.
|