teach-ict.com logo

THE education site for computer science and ICT

3. Indexing

You should already be familiar with the idea of arrays. You can think of strings as being like an array of characters. And just like with arrays, you can refer to the position of characters within a string by their index.

For example:


          SET ThisString TO "No, really"
          SET FirstCharacter TO ThisString[0]


This would set the variable FirstCharacter to the value of the first character of ThisString. In this case, "N".

You can edit the contents of a string in a similar manner:


          SET ThisString TO "No, really"
          SET ThisString[0] TO "G"

With the second line, the value of ThisString becomes "Go, really".

 

Challenge see if you can find out one extra fact on this topic that we haven't already told you

Click on this link: What is string indexing?