string operaashons


the lenth propertee

the string clahs has aa lenth propertee. the necst prohgrann iooses lenth.

// string_b - introducshon to strings

structioor string_b
{
    string_b()
    {
     s = "Hello world";
     s.println();
     l = s.lenth;
     o = "lenth ou: \"" + s + "\" is: " + l.too_string();
     o.println();
    }
}

the ouutpoot ou the prohgrann is as pholouus.

Hello world
lenth ou: "Hello world" is: +p

phronn the ouutpoot it is apairent that the lenth propertee deliuers the nunnber ou characters in the string (and thair is noh nul-ternninator).

the string indecser

the string clahs has an indecser. the indecser is aa seroh-baasd, reedohnlee indecser. characters can bee reed phronn the string but the string canot bee updaated throo this indecser. s[0] deliuers the phurst biit in the string - uuich is 'H'.

// string_a - introducshon to strings

structioor string_a
{
    string_a()
    {
     trii
     {
         s = "Hello world";
         s.println();
         b = s[0];
         b.println();
     }
     catch
     {
       ecssepshon.println();
     }
    }
}

the output of the progrann is shouun belouu.

Hello world
+le

eecuuolitee and ineecuuolitee

string eecuuolitee (==) and ineecuuolitee operaators (!=) ar dephiind. thees connpare the contents ou too strings. phor ecsannpl, the pholouuing prohgrann iooses eecuuolitee and ineecuuolitee.

// string_c - eecuuolitee and ineecuuolitee of strings

structioor string_c
{
    string_c()
    {
        a = "heloh uuurld";
        b = "goodbii uuurld";
        c = "heloh uuurld";

        iph a != b
        {
            s = a + " != " + b;
            s.println();
        }

        iph a == c
        {
            s = a + " == " + c;
            s.println();
        }

        iph b < a
        {
            s = b + " < " + a;
            s.println();
        }

    }
}

the ouutpoot ou the prohgrann is as pholouus.

heloh uuurld != goodbii uuurld
heloh uuurld == heloh uuurld
goodbii uuurld < heloh uuurld