首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C#文本有关问题

2013-09-05 
C#文本问题一个小问题,就是文本超出指定的长度时,显示省略号c#[解决办法] static void Main(string[] args

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;

热点排行