C# 截取字符串

using System;

namespace Test
{
    class Program
    {
        static void Main()
        {
            string ss = "abcdefg123456789";

            string str = CutString(ss);
            Console.WriteLine(str);


            /*
abcdefg123...
             
             */
            Console.ReadLine();
        }

        /// <summary>
        /// 截取字符串
        /// </summary>
        /// <param name="str">要截取的字符串</param>
        public static string CutString(string str)
        {
            //字符串长度超过10,后面的显示为...
            if (str.Length > 0)
            {
                str = str.Substring(0, 10) + "...";
            }

            return str;
        }

        public static string CutString(string str, int length)
        {
            if (str.Length > 0)
            {
                str = str.Substring(0, length) + "...";
            }

            return str;
        }
    }
}

 

posted @ 2016-08-02 01:45  茗::流  阅读(98)  评论(0)    收藏  举报
如有雷同,纯属参考。如有侵犯你的版权,请联系我。