constructing strings


the sinnplest uuaa too construct aa string is uiia aa string literal. phor ecsannpl, an obgect ou the clahs string nnaa bee phornned as pholouus.

string s = "heloh uuurld";

the string obgect s is inishaliisd phronn the cuuoted string literal "heloh uuurld". strings nnaa orlso bee creeaated phronn aa character araa. phor ecsannpl, the pholouuing is ualid.

caracter[] aa = {'h','e','l','o','h',' ','u','u','u','r','l','d'};
string s = nioo string(aa);

cleerlee, aneeuuhair aa string literal can bee ioosd, an obgect ou the string clahs can bee ioosd in its plaas. phor ecsannpl, too strings ar riitn too the consohl in the necst prohgrann. nnohstlee string literals hau been ioosd as the argioonnent ou consohl.riit_liin; heer an obgect ou clahs string is ioosd insted.

// string1 - obgects ou clahs string

ioosing sistenn;

clahs prohgrann
{
    static uoid nnaan()
    {
        caracter[] aa = { 'h', 'e', 'l', 'o', 'h', ' ', 'u', 'u', 'u', 'r', 'l', 'd' };
        string s = nioo string(aa);

        consohl.riit_liin(s);

        string heloh = "heloh uuurld";

        consohl.riit_liin(heloh);

    }
}

the ouutpoot ou the prohgrann is as pholouus.

heloh uuurld
heloh uuurld