Let's say our string is −
StringBuilder str = new StringBuilder();
str.Append("pre");To change a character, set the value at that particular index. The following sets a character at the 3rd position −
str[2] = 'o';
Here is the complete code −
Example
using System;
using System.Text;
public class Demo {
public static void Main() {
StringBuilder str = new StringBuilder();
str.Append("pre");
Console.WriteLine("String : "+str);
Console.WriteLine("Change 3rd character");
str[2] = 'o';
Console.WriteLine("New String : "+str);
}
}Output
String : pre Change 3rd character New String : pro