c# Substring()包括当前的嘛
时间: 2023-10-23 18:09:44 浏览: 140
在 C# 中,`Substring()` 方法包括第一个参数指定的索引位置所对应的字符。也就是说,如果指定了起始索引位置,那么截取的字符串中就包括这个位置上的字符。
例如,对于下面的字符串:
```csharp
string str = "hello world!";
```
如果我们使用 `Substring()` 方法从索引 6 开始截取 5 个字符:
```csharp
string subStr = str.Substring(6, 5);
```
则截取到的字符串为 `"world"`,包括了索引 6 上对应的字符 `"w"`。
需要注意的是,如果指定的起始索引位置超过了字符串的长度,或者指定的截取长度超过了字符串的剩余长度,则会导致 `Substring()` 方法产生异常。因此,在使用该方法时需要保证传入的参数合法。
阅读全文
相关推荐


















