c中substring的用法
c中substring的用法的用法你知道吗?下面小编就跟你们详细介绍下c中substring的用法的用法,希望对你们有用。
c中substring的用法的用法如下:
String.SubString(int index,int length)
index:开始位置,从0开始
length:你要取的子字符串的长度
示例:
using System;
using System.Collections.Generic;
using System.Text;
nameSPAce str_sub
{
class Program
{
static void Main(string[] args)
{
string myString = "Hello Word!";
https://Substring()在C#中有两个重载函数
https://分别如下示例
string subString1 = myString.Substring(0);
https://如果传入参数为一个长整, 且大于等于0,
https://则以这个长整的位置为起始,
https://截取之后余下所有作为字串.
https://如若传入值小于0,
https://系统会抛出ArgumentOutOfRange异常
https://表明参数范围出界
string subString2 = myString.Substring(0, 5);
https://如果传入了两个长整参数,
https://前一个为参数子串在原串的起始位置
https://后一个参数为子串的长度
https://如不合条件同样出现上述异常
Console.WriteLine(subString1);
Console.WriteLine(subString2);
Console.ReadLine();
}
}
}
程序输出的结果:
Hello Word!
Hello