C#截取字符串函数是什么样子的呢?这个在实际工作中我们经常会遇见这样的实际应用问题,那么具体的解决方案是什么呢?下面就向你介绍C#截取字符串函数的实现:

创新互联长期为上千家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为新罗企业提供专业的网站建设、做网站,新罗网站改版等技术服务。拥有10多年丰富建站经验和众多成功案例,为您定制开发。
C#截取字符串函数实例:
- //C#截取字符串函数
- public string CutStr(string sInString,int iCutLength){
- if(sInString==null ||
- sInString.Length==0 || iCutLength<=0) return "";
- int iCount=System.Text.Encoding.
- GetEncoding("Shift_JIS").GetByteCount(sInString);
- if(iCount>iCutLength){
- int iLength=0;
- //C#截取字符串函数
- for(int i=0;i
- int iCharLength=
- System.Text.Encoding.GetEncoding("Shift_JIS").
- GetByteCount(new char[]{sInString[i]});
- iLength += iCharLength;
- if(iLength==iCutLength){
- sInString=sInString.Substring(0,i+1);
- break;
- //C#截取字符串函数
- }else if(iLength>iCutLength){
- sInString=sInString.Substring(0,i);
- break;
- }
- }
- }
- return sInString;
- }
C#截取字符串函数的相关信息就向你介绍到这里,希望对你了解和学习C#截取字符串函数有所帮助。