String.SubString

1理论

String.SubString(int index,int length)

index:开始位置,从0开始

length:你要取的子字符串的长度

2实验

       string my = "daydayup";

            string s1 = my.Substring(0);//不指明长度,默认截取后面所有。

            string s2 = my.Substring(3, 5);//从第3个长度开始截取,截取5个长度。

            string s3 = my.Substring(7);//从第7个长度开始截取,默认截取后面所有。

 

            Console.WriteLine(s1);

            Console.WriteLine(s2);

            Console.WriteLine(s3);

            Console.Read();

输出:

daydayup

dayup

p

 

 3加入符号和空格

            string my = "To,day up";

            string s1 = my.Substring(0);

            string s2 = my.Substring(2, 3);

            string s3 = my.Substring(5);

 

            Console.WriteLine(s1);

            Console.WriteLine(s2);

            Console.WriteLine(s3);

            Console.Read();

 输出

To,day up

,da

y up

 

posted @ 2016-11-25 14:14  hao_1234_1234  阅读(208)  评论(0)    收藏  举报