string str="张三李四王五";
Console.WriteLine(str.Substring(str.Length,str.Length-1));这样应该能截取 最后一个字符吧 为什么在我这运行的报错呢
我写死试的 1-4以下 能截 2-4 3-4 都 截不了了报错
substringString
Console.WriteLine(str.Substring(str.Length,str.Length-1));这样应该能截取 最后一个字符吧 为什么在我这运行的报错呢
我写死试的 1-4以下 能截 2-4 3-4 都 截不了了报错
substringString
public string Substring(int startIndex);//参数为起始索引位置,截取从该位置到字符串的末尾之间的字串
public string Substring(int startIndex, int length);//两个参数分别为:起始索引位置,截取的长度
按照你的代码str.Substring(str.Length,str.Length-1),用到的是第二个
因为字符串的索引是从0开始的,最后一个是str.Length-1。所以你给的第一个参数已经越界了
Response.Write(str.Substring(str.Length - 1, 1));