C#截取字符串后几位
时间: 2023-08-29 22:06:42 浏览: 401
C#字符串截取
3星 · 编辑精心推荐
要在C#中截取字符串的后几位,有几种方法可以实现。
第一种方法是使用`Substring`函数。首先,将字符串赋值给一个变量,然后使用`Substring`函数来截取字符串的后几位。例如,如果要截取字符串的后5位,可以使用以下代码:
```
string str = "GTAZB_JiangjBen_123";
int i = 5;
string tSt = str.Substring(str.Length - i);
Console.WriteLine(tSt);
```
这将输出 "n_123"。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [C#中截取字符串的几种方法](https://blog.csdn.net/qq_36664495/article/details/80352602)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [C#几种截取字符串的方法(split 、Substring、Replace、remove)](https://blog.csdn.net/weixin_27653327/article/details/113377912)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文