/// <summary>
/// C#中英文混合字符串截取指定长度
/// 注:英文为一个字符,中文算两个字符
/// </summary>
/// <paramname="Str">原始字符串</param>
/// <paramname="Len">长度[小等于0返回全部]</param>
/// <paramname="StrMore">省略号(可为空)</param>
///<returns></returns>
public static string GetSubStr(string Str, int Len, stringStrMore)
{
if (string.IsNullOrEmpty(Str))
return "";
string outstr = string.Empty;
int n = 0;
foreach (char ch in Str)
{
n +=System.Text.Encoding.Default.GetByteCount(ch.ToString());
if (n > Len)
{
if(StrMore != null)
outstr += StrMore;
break;
}
else
outstr += ch;
C#中英文混合字符串截取指定长度
最新推荐文章于 2015-07-23 12:43:00 发布