c#-replace a character at a given index of a string

Categories: Programming
Tags: No Tags
Comments: No Comments
Published on: July 22, 2010

Following method replaces a character at a given index of a string.

// Replaces a character in a string with the character specified.
void replaceCharWithChar(ref string text, int index, char charToUse)
{
char[] tmpBuffer = text.ToCharArray();

tmpBuffer [index] = charToUse;

text = new string(tmpBuffer);
}

Share this

Welcome , today is Tuesday, February 7, 2012

Bad Behavior has blocked 251 access attempts in the last 7 days.