繁体中文
设为首页
加入收藏
当前位置:程序开发首页 >> 其他开发语言 >> 字符串处理:中英文混排固定长度截取问题

字符串处理:中英文混排固定长度截取问题

2006-09-09 01:01:12  作者:虫虫  来源:互联网  浏览次数:9  文字大小:【】【】【
简介:从包含中英文的字符串中截取固定长度的一段,strInput为传入字符串,intLen为截取长度(一个汉字占两个位)。/// <summary>  /// 从包含中英文的字符串中截取固定长度的一段,strInput为传入字符...

从包含中英文的字符串中截取固定长度的一段,strInput为传入字符串,intLen为截取长度(一个汉字占两个位)。

///

/// 从包含中英文的字符串中截取固定长度的一段,strInput为传入字符串,intLen为截取长度(一个汉字占两个位)。

///

public string cutString(string strInput,int intLen)

{

strInput=strInput.Trim();

byte[] myByte = System.Text.Encoding.Default.GetBytes(strInput);

if(myByte.Length>intLen)

{

//截取操作

string resultStr="";

for(int i=0;i

byte[] tempByte=System.Text.Encoding.Default.GetBytes(resultStr);

if(tempByte.Length

{

resultStr+=strInput.Substring(i,1);

}

else{

break;

}

}

return resultStr+" ...";

}

else{

return strInput;

}

}

责任编辑:admin
相关文章