C#中怎么实现一个截取字符串函数,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。C#截取字符串函数实例://C#截取字符串函数 public
C#中怎么实现一个截取字符串函数,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。
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<sInString.Length;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; }
看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注编程网精选频道,感谢您对编程网的支持。
--结束END--
本文标题: C#中怎么实现一个截取字符串函数
本文链接: https://www.lsjlt.com/news/293969.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-10
2024-05-10
2024-05-10
2024-05-10
2024-05-10
2024-05-10
2024-05-10
2024-05-10
2024-05-10
2024-05-10
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0