string
a = "hello world!";
string
b = a.Substring(6); //获取下标为6以后的全部字符。
string
c = a.Substring(6, 2); //获取下标为6以后的2个字符。
Console.WriteLine(b);
Console.WriteLine(c);
string
d = a.Insert(0, "pkm "); //在下标为0之前插入"pkm
"
Console.WriteLine(d);
string
e = d.Insert(d.Length - 1, " good"); //在下标为长度减1(最后一个)前插入" good"
Console.WriteLine(e);
string
f = a.Remove(6); //删除下标从6开始的后面的全部字符
Console.WriteLine(f);
string
g = a.Remove(6, 2); //删除下标从6开始的后面的2个字符
Console.WriteLine(g);
string
h = a.Replace('!', '*'); //将!替换为
*
Console.WriteLine(h);
string
i = a.Replace("hello", "HELLO"); //将hello
替换成 HELLO
Console.WriteLine(i);
//转义字符@ 下面的 j==k
string
j = "C:\temp\temp1\temp2";
Console.WriteLine(j);
string
k = @"C:temptemp1temp2";
Console.WriteLine(k);
//StringBuilder是可变的字符串(string是不可变的,修改长度要重新开辟空间)
//定义使用方法如下:
StringBuilder
l = new StringBuilder("hello", 50);//
l.Append("
world");
Console.WriteLine(l);
l.AppendFormat("{0}
end", "!");
Console.WriteLine(l);
l.AppendLine("
one line");
Console.WriteLine(l);