Replace char at index
Replace one char at index
Source
public static string ReplaceAtIndex(this string text, int index, char c)
{
var stringBuilder = new StringBuilder(text);
stringBuilder[index] = c;
return stringBuilder.ToString();
}
Example
Console.WriteLine("012345".ReplaceAtIndex(1,'I').ReplaceAtIndex(3,'T'));
// Output: 0I2T45
©2007-2024 ExtensionMethod.NET.
ExtensionMethod.NET was built by Loek van den Ouweland and Fons Sonnemans
with ASP.NET Core, HTML, CSS, Javascript, SQL Server and some of the great methods you have posted here.
By using this website, you agree to the legal stuff .
We thank all who contributed to this website for the last twelve years. It really helped making this website a success!
Looking for Visual Studio Code Snippets? Visit our sister site VisualStudioCodeSnippets.com .