C#几个经常用到的字符串截取
一、字符串截取问题:
//1.<Case No.> = <Centre Code>/current year/#####, ##### = same no. from <Case Profile No>
Case Profile No:CAP-0001003-2022-00143 Case No.:0001003/2022/00143
entity.crms_case_no = entity.crms_case_profile_no.Remove(0, 4).Replace("-", "/");
二、扩展常用字符串
1. 取字符串的前i个字符
string str1=str.Substring(0,i);
string str1=str.Remove(i,str.Length-i);
2. 去掉字符串的前i个字符
string str1=str.Remove(0,i);
string str1=str.SubString(i);
3.从右边开始取i个字符:
string str1=str.SubString(str.Length-i);
string str1=str.Remove(0,str.Length-i);
4.从右边开始去掉i个字符:
string str1=str.Substring(0,str.Length-i);
string str1=str.Remove(str.Length-i,i);
5.如果字符串中有"abc"则替换成"ABC"
str=str.Replace("abc","ABC");
6.c#截取字符串最后一个字符
str1.Substring(str1.LastIndexOf(",")+1);
k = k.Substring(k.Length-1, 1);
三、参考资料
https://www.cnblogs.com/lykbk/archive/2012/06/28/lyk1232132.html
备注:20220209
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
2019-02-14 每日问题