Strings

We touched briefly on strings last chapter. I want to give you more examples, because knowing how to work with strings and sequences will be a key skill when using Euphoria.

Here are some examples of sequences and strings.

x = "My name is Johnny." -- a string
y = { "My name is Johnny." } -- a sequence of ONE element, which happens to be a string
z = { y } -- a sequence containing a sequence that contains a string
a = {"One","Two","Three"} -- a sequence of strings
b = "String" -- another simple string
c = {'S','t','r','i','n','g'} -- a sequence of six atoms which happens to be equal to b above
-- print b and c if you don't believe me

Here are some examples of subscripting strings.

x[4..7] is "name"
y[1][4..7] is "name"
z[1][1] is "My name is Johnny."
a[2] is "Two"
b[3] is 'r' -- notice that the third element of "String" is the atom 'r'
c[3] is 'r'

d = z[1][1][4..7] -- d now equals "name"

Here are some examples of appending and otherwise manipulating strings.

e = x & " " & a[3] -- e now equals "My name is Johnny. Three"
f = b[1..3]
g = b[3..6]
puts(1, f & g) -- outputs "Strring"
puts(1, g[1..length(g)]) -- outputs "ring"

Onward!