コード例 #1
0
        internal static string GetSafeStringWithoutTrim(string text, int length)
        {
            text = text;
            int      byteCount = ToolUtil.GetByteCount(text);
            Encoding encoding  = ToolUtil.GetEncoding();

            byte[] bytes = encoding.GetBytes(text);
            if (bytes.GetLength(0) <= length)
            {
                return(text);
            }
            byte num3  = bytes[length - 1];
            int  index = length - 1;

            while ((bytes[index] >= 0xa1) && (bytes[index] <= 0xfe))
            {
                index--;
                if (index < 0)
                {
                    break;
                }
            }
            if (((length - index) % 2) == 0)
            {
                length--;
            }
            return(encoding.GetString(bytes, 0, length));
        }
コード例 #2
0
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            string text = this.textBox1.Text;

            for (int i = ToolUtil.GetByteCount(text); i > 20; i = ToolUtil.GetByteCount(text))
            {
                int length = text.Length;
                text = text.Substring(0, length - 1);
            }
            this.textBox1.Text           = text;
            this.textBox1.SelectionStart = this.textBox1.Text.Length;
        }
コード例 #3
0
 public static string GetSubString(string s, int len)
 {
     if ((s == null) || (s.Length == 0))
     {
         return(string.Empty);
     }
     if (ToolUtil.GetByteCount(s) > len)
     {
         for (int i = s.Length; i >= 0; i--)
         {
             s = s.Substring(0, i);
             if (ToolUtil.GetByteCount(s) <= len)
             {
                 return(s);
             }
         }
     }
     return(s);
 }
コード例 #4
0
ファイル: Class34.cs プロジェクト: SoL-Alucard-Git/HX-Base
        internal static string smethod_23(string string_0, int int_0, bool bool_0, bool bool_1 = true)
        {
            string str = string_0;

            if (bool_1 && (string_0 != null))
            {
                string[] strArray2 = string_0.Split(new string[] { "\r\n", "\n", "\r" }, StringSplitOptions.RemoveEmptyEntries);
                str = (strArray2.Length == 0) ? "" : strArray2[0];
            }
            if ((str != null) && (str.Length != 0))
            {
                int byteCount = ToolUtil.GetByteCount(str);
                if (byteCount <= int_0)
                {
                    if (bool_0)
                    {
                        return(new StringBuilder(str).Append(new string(' ', int_0 - byteCount)).ToString());
                    }
                    return(str);
                }
                for (int i = str.Length; i >= 0; i--)
                {
                    str = str.Substring(0, i);
                    if (ToolUtil.GetByteCount(str) <= int_0)
                    {
                        return(str);
                    }
                }
                return("");
            }
            if (!bool_0)
            {
                return(string.Empty);
            }
            return(new string(' ', int_0));
        }