首页 > 其他 > 详细

3月5日 String类

时间:2015-03-05 18:43:07      阅读:213      评论:0      收藏:0      [点我收藏+]

1.Length    --取字符串长度

string x = Console.ReadLine();
            int i = x.Length;
            Console.WriteLine(i);

执行结果:

技术分享

2.Substring(从哪一位开始,截取几位)   --截取字符串,从第六位往后截取3位,包括空格在内

string x = Console.ReadLine();
           string p = x.Substring(6, 3);
           Console.WriteLine(p);

执行结果:

技术分享

3.Trim()  --压缩前后空格     TrimStart():压缩前面空格    TrimEnd():压缩后面空格

string x = Console.ReadLine();
         int i = x.Length;
         Console.WriteLine(i);

         string s = x.Trim();
         Console.WriteLine(s);

         int p = s.Length;
         Console.WriteLine(p);

执行结果:

技术分享

4.ToLower()所有大写都转成小写

ToUpper()所有小写都转成大写

string x = Console.ReadLine();
       x = x.ToLower();
       Console.WriteLine(x);
       x = x.ToUpper();
       Console.WriteLine(x);

执行结果:

技术分享

5.Replace("被替换的","替换为")  --替换字符  (前面是被替换的,后面是替换成的)

 

    string x = Console.ReadLine();
          string p = x.Replace("a", "A");
          Console.WriteLine(p);

执行结果:

技术分享

 

 

 

6.Remove(从哪一位开始,删除几位)   --删除字符

string x = Console.ReadLine();
            x=x.Remove(5,3);
            Console.WriteLine(x);

执行结果:

技术分享

7.Split(Char[])    --分隔字符串

string words = "This is a list of words, with: a bit of punctuation" +
                     "\tand a tab character.";
            string[] str = words.Split(new Char[] { ‘ ‘, ‘,‘, ‘.‘, ‘:‘, ‘\t‘ });
            foreach (string s in str)
            {
                if (s.Trim() != "")
                    Console.WriteLine(s);
            }

执行结果:

技术分享

3月5日 String类

原文:http://www.cnblogs.com/tzq9308/p/4316274.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!