我有一个大字符串,它存储在字符串变量str中.我想从c#中得到一个子串?假设字符串是:" Retrieves a substring from this instance. The substring starts at a specified character position."
子串结果我要显示的是: The substring starts at a specified character position.
as-*_*cii 20
您可以手动或使用IndexOf方法执行此操作.
手动:
int index = 43;
string piece = myString.Substring(index);
Run Code Online (Sandbox Code Playgroud)
使用IndexOf,您可以看到fullstop的位置:
int index = myString.IndexOf(".") + 1;
string piece = myString.Substring(index);
Run Code Online (Sandbox Code Playgroud)
ric*_*ard 19
string newString = str.Substring(0,10)
Run Code Online (Sandbox Code Playgroud)
将给出前10个字符(从位置0到位置9).
看到这里.
| 归档时间: |
|
| 查看次数: |
112179 次 |
| 最近记录: |