按字节截取字符串,结尾加..

时间:2013-12-20 09:52:31
【文件属性】:

文件名称:按字节截取字符串,结尾加..

文件大小:2KB

文件格式:CS

更新时间:2013-12-20 09:52:31

StringBuilder StringHelper Encoding Unicode ...

int iCnt = 0; int i_index; int i_len; System.Text.StringBuilder strRet = new System.Text.StringBuilder(); i_len = strVal.Length; byte[] chrbyte; System.Text.Encoding encoding = System.Text.Encoding.Unicode; chrbyte = encoding.GetBytes(strVal); for (i_index = 1; i_index < (chrbyte.Length); i_index = i_index + 2) { iCnt++; if (chrbyte[i_index] != 0) { iCnt++; } if (iCnt <= iLength) { byte[] va = new byte[2]; va[0] = chrbyte[i_index - 1]; va[1] = chrbyte[i_index]; strRet.Append(encoding.GetString(va)); } else { if (i_index < chrbyte.Length + 1) { strRet.Append("..."); } break; } }


网友评论