<- First Steps
New names for old things ->

Strings

So that's numbers... but what about letters? Words? Text?

The word we use for groups of characters is string. Here are some strings:

Some things you can do with 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.

More things you can do with text

Here are some more nifty things you can do with text:

Exercises

  1. What do you expect these will do?:

    
       "hello".length + "world".length   
       "".empty?
       "Zoo".include? "oo"   
       "cute".chop
                           

    Try them!

  2. Spell your name backwards.

  3. What might "Daniel".reverse.reverse produce?

  4. Spell your name backwards, make it lowercase, and capitalize the first letter.
    Try it with family members' names, the neighbor's dog, etc.

  5. What do you think happens if you don't make the name lowercase first? (in the above exercise). Try it.

  6. What is special about this phrase: "A man a plan a canal Panama"?

  7. A palindrome is a word or phrase that looks the same if you write it backwards. Here are some palindromes:

  8. Play around with strings for a bit.

<- First Steps
New names for old things ->