您的位置:首页 > 其它

string 类型的使用方法

2015-10-30 11:40 239 查看
           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);
    
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: