C# relationship between chars and strings

05/04/2008 07:58 Lateralus#1
I know that chars are wrappers around a string, but how would I declare an array able to change one of the characters in the string?
05/04/2008 11:48 hok30#2
Did you already post this in the [Only registered and activated users can see links. Click Here To Register...] Or the [Only registered and activated users can see links. Click Here To Register...] section? Or do you just want somone from this section to handle it.
05/04/2008 11:50 tanelipe#3
I don't know if there is a easier way to do this but :

If you want to replace all specified chars in string :
Code:
string myString = "Hello World!";
            Console.WriteLine("This is what it's at the start : " + myString);
            myString = myString.Replace("l", "x");
            Console.WriteLine("nThis is what it's after the change : " + myString);
            //This is what it's at the start : Hello World
            //This is what it's after the change Hexxo Worxd
If you want to replace a specified character at specified place :

Code:
 string  myString = "Hello World!";

            char[] Array = myString.ToCharArray();
            Array[0] = 'X';
            myString = "";
            for (int i = 0; i < Array.Length; i++)
                myString += (char)Array[i];
            Console.WriteLine(myString);

            // Output : Xello World!
Hope it helps to right direction atleast. :P