Learn Ruby

First position is zero not 1

We want the know the first letter of the string hello.

In Ruby the first position is 0 and not 1. So we start counting from 0. First letter is at position 0. Second letter is at position 1.

Computer science folks call it index rather than calling it position. So we can say that first letter is at index 0. Second letter is at index 1 and so on.

String h e l l o
Index 0 1 2 3 4

Similarly if we want the 3rd letter then we need to use value 2.

Let’s see one more example.

String c h i c a g o
Index 0 1 2 3 4 5 6