|          
/// <summary>/// 从包含中英文的字符串中截取固定长度的一段,strInput为传入字符串,intLen为截取长度(一个汉字占两个位)。
 /// </summary>
 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<strInput.Length;i++){
 byte[] tempByte=System.Text.Encoding.Default.GetBytes(resultStr);
 if(tempByte.Length<intLen-4)
 {
 resultStr+=strInput.Substring(i,1);
 }
 else{
 break;
 }
 }
 return resultStr+" ...";
 }
 else{
 return strInput;
 }
 }
 
 
 |