设置StringBuilder-
StringBuilder str = new StringBuilder("Airport");
假设您需要删除字符。为此,请使用Remove()方法,该方法删除以特定索引开头的一堆字符-
str.Remove(3, 4);
上面的代码从第3个索引(即第4个位置)删除了四个字符-
这是完整的代码-
using System; using System.Text; public class Program { public static void Main() { StringBuilder str = new StringBuilder("Airport"); Console.WriteLine("String: "+str); // removing four characters Console.Write("String after removing characters: "); str.Remove(3, 4); Console.WriteLine(str); } }
输出结果
String: Airport String after removing characters: Air