截取字付串

public static string GetString(string str, int length )
        {
            int i = 0, j = 0;
            foreach (char chr in str)
            {
                if ((int)chr >30)
                {
                    i += 2;
                }
                else
                {
                    i++;
                }
                if (i > length)
                {
                    str = str.Substring(0, j) + "...";
                    break;
                }
                j++;
            }
            return str;

        }
        #endregion

你可能感兴趣的:(截取)