C#截取字符串函數(shù)實(shí)例解析
作者:netshahuhu
C#截取字符串函數(shù)是如何實(shí)現(xiàn)的呢?C#截取字符串函數(shù)使用到了什么方法呢?那么這里向你展示了C#截取字符串函數(shù)實(shí)例的實(shí)現(xiàn)方法,希望對你有所幫助。
C#截取字符串函數(shù)是什么樣子的呢?這個(gè)在實(shí)際工作中我們經(jīng)常會遇見這樣的實(shí)際應(yīng)用問題,那么具體的解決方案是什么呢?下面就向你介紹C#截取字符串函數(shù)的實(shí)現(xiàn):
C#截取字符串函數(shù)實(shí)例:
- //C#截取字符串函數(shù)
- 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#截取字符串函數(shù)
- 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#截取字符串函數(shù)
- }else if(iLength>iCutLength){
- sInString=sInString.Substring(0,i);
- break;
- }
- }
- }
- return sInString;
- }
C#截取字符串函數(shù)的相關(guān)信息就向你介紹到這里,希望對你了解和學(xué)習(xí)C#截取字符串函數(shù)有所幫助。
【編輯推薦】
責(zé)任編輯:仲衡
來源:
百度空間