在 C# StringBuilder 中访问字符
首先,设定 StringBuilder −
StringBuilder str = new StringBuilder(); str.Append("premium");
要访问第 5 个字符并显示它 −
Console.WriteLine(str[4]);
以下为完整代码 −
示例
using System; using System.Text; public class Demo { public static void Main() { StringBuilder str = new StringBuilder(); str.Append("premium"); Console.WriteLine("String : "+str); Console.Write("Accessing 5th character : "); Console.WriteLine(str[4]); } }
输出
String : premium Accessing 5th character : i
广告