zoukankan      html  css  js  c++  java
  • 字符串宽相同

     private static string stringformat(string value, int Len)
        {
            string result = "";
            result = GetSubString(value, Len);

            int rlen = System.Text.Encoding.Default.GetByteCount(result);
            int nlen = (Len * 2) + 3;
            if (rlen < nlen)
            {
                for (int j = 0; j < (nlen - rlen); j++)
                {
                    result = result + "&nbsp;";
                }
            }
            return result;
        }

        public static string GetSubString(string value, int Len)
        {
            if (value.Length < Len)
                return value;

            int halfwordcount = 0;

            for (int i = 0; i < Len; i++)
            {
                if (CheckHalfWord(value[i].ToString()))
                {
                    halfwordcount++;
                }
            }
            if (halfwordcount == 0)
            {
                return value.Substring(0, Len) + "...";
            }
            else
            {
                if (value.Length > Len + halfwordcount / 2)
                    return value.Substring(0, Len) + GetSubString(value.Substring(Len), halfwordcount / 2);
                else
                    return value;
            }
        }

        private static bool CheckHalfWord(string value)
        {
            if (1 == System.Text.Encoding.Default.GetByteCount(value))
            {
                return true;
            }
            else
            {
                return false;
            }
        }

  • 相关阅读:
    Pure-ftpd无法连接到服务器 425错误
    jQuery 取选中的radio的值方法
    Linux中RM快速删除大量文件/文件夹方法
    CSS(七):浮动
    CSS(六):盒子模型
    CSS(五):背景、列表、超链接伪类、鼠标形状控制属性
    CSS(四):字体和文本属性
    CSS三:CSS的三种引入方式
    CSS(二):选择器
    CSS(一):CSS简介和基本语法
  • 原文地址:https://www.cnblogs.com/lgxll/p/2555632.html
Copyright © 2011-2022 走看看