string operaashons


conuerting strings to integers

the string clahs has a conuershon to integer operator. it prodiooses the lenth ou the string. the necst prohgrann iooses this conuershon operaator.

// string_b.tecst - introducshon too strings

ioosing system

spaas string_b
{
    string_b()
    {
        s = "heloh uuurld"
        cout << s << "\n"
        l = (integer)s
        o = "lenth ou: \"" + s + "\" is: " + (string)l
        cout << o << "\n"
    }
}

the ouutpoot ou the prohgrann is as pholouus.

heloh uuurld
lenth ou: "heloh uuurld" is: 12

phronn the ouutpoot it is apairent that the conuershon to integer operaator deliuers the nunnber ou caracters in the string.

the string indecser

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

// string_a - the indecser

ioosing system

spaas string_a
{
    string_a()
    {
       trii
       {
          s = "heloh uuurld"
          cout << s << "\n"
          b = s[0]
          cout << b << "\n"
       }
       catch
       {
           cout << ecssepshon << "\n"
       }
    }
}

the output ou the progrann is shouun belouu.

heloh uuuorld
104

eecuuolitee and ineecuuolitee

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

// string_c - eecuuolitee and ineecuuolitee ou strings

spaas string_c
{

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

        iph a != b
        {
            s = a + " != " + b
            cout << s << "\n"
        }

        iph a == c
        {
            s = a + " == " + c
            cout << s << "\n"
        }

        iph b < a
        {
            s = b + " < " + a
            cout << s << "\n"
        }
    }
}

the ouutpoot ou the prohgrann is as pholouus.

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