动态串StringBuilder的操作方法
昨日、ブン川で、大規模な地震が襲った。
StringBuilder常用的方法:
1.追加:Append, AppendFormat
2.插入:Insert
3.删除:Remove
4.替换:Replace
为灾区人民祈福!
StringBuilder常用的方法:
1.追加:Append, AppendFormat
2.插入:Insert
3.删除:Remove
4.替换:Replace
class Program
{
static void Main(string[] args)
{
Console.WriteLine("----------------------------test Append");
StringBuilder sb = new StringBuilder("Hello",100);
sb.Append(" World !");
Console.WriteLine(sb);
Console.WriteLine("----------------------------test Insert");
sb = new StringBuilder("Hello");
sb.Insert(2,"sss");
Console.WriteLine(sb); //结果为:Hesssllo
Console.WriteLine("----------------------------test Remove");
sb = new StringBuilder("Hello");
sb.Remove(2,3);
Console.WriteLine(sb); //结果为:He
Console.WriteLine("----------------------------test Replace");
sb = new StringBuilder("Hello");
sb.Replace("l", "M");
Console.WriteLine(sb); //结果为:HeMMo
}
}
{
static void Main(string[] args)
{
Console.WriteLine("----------------------------test Append");
StringBuilder sb = new StringBuilder("Hello",100);
sb.Append(" World !");
Console.WriteLine(sb);
Console.WriteLine("----------------------------test Insert");
sb = new StringBuilder("Hello");
sb.Insert(2,"sss");
Console.WriteLine(sb); //结果为:Hesssllo
Console.WriteLine("----------------------------test Remove");
sb = new StringBuilder("Hello");
sb.Remove(2,3);
Console.WriteLine(sb); //结果为:He
Console.WriteLine("----------------------------test Replace");
sb = new StringBuilder("Hello");
sb.Replace("l", "M");
Console.WriteLine(sb); //结果为:HeMMo
}
}
为灾区人民祈福!