關鍵代碼如下:

/// <summary>/// 估算中英文字符串的寬度/// </summary>/// <returns></returns>public static double GetWidthUnitCount(string value){    double count = 0;    for (var i = 0; i < value.Length; i++)    {        if (IsChinese(value[i].ToString()) == true)        {            count += 2;        }        else if (IsUpChar(value[i].ToString()) == true)        {            count += 1.5;        }        else        {            count += 1;        }    }    return count;}/// <summary>/// 是否漢字或中文標點/// </summary>PRivate static bool IsChinese(string value){    Regex reg = new Regex("[/u4E00-/u9FFF]|[/uFE30-/uFFA0]");    return reg.IsMatch(value);}/// <summary>/// 是否大寫字母/// </summary>private static bool IsUpChar(string value){    Regex reg = new Regex("[A-Z]");    return reg.IsMatch(value);}View Code新聞熱點
疑難解答