
Replaces a character in a string with a new character.
Instructions:
1) Copy and paste this snippet into a class.
2) Read the example usage.
// Replaces a character in a string with the character specified.
void replaceCharWithChar(ref string text, int index, char charToUse)
{
char[] tmpBuffer = text.ToCharArray();
buffer[index] = charToUse;
text = new string(tmpBuffer);
}
// Example Usage
string helloWorld = "Hello World";
replaceCharWithChar(helloWorld, 0, helloWorld[0].ToLower());EDIT: Changed the example to turn the first character into a lower case character instead of an upper case character.. how silly of me. =}
-Offline- |