日期:2014-05-17  浏览次数:20891 次

C#文本问题
一个小问题,就是文本超出指定的长度时,显示省略号
c#

------解决方案--------------------
 static void Main(string[] args)
        {
            string result = 处理字符串("hello world hello world hello world hello world hello world hello world");
            Console.WriteLine(result);
        }

        public static string 处理字符串(string str)
        {
            if (str.Length > 20)
            {
                return str.Substring(0, 20) + "...";
            }
            return str;
        }

------解决方案--------------------
本帖最后由 caozhy 于 2013-08-27 15:03:40 编辑
int max = ...
s = s.Length > max ? s.SubString(0, max) + "..." : s;