Ellipses the specified STR. - CSharp System

CSharp examples for System:String Shorten

Description

Ellipses the specified STR.

Demo Code


using System.Xml.Serialization;
using System.Text.RegularExpressions;
using System.Text;
using System.Reflection;
using System.IO;//w w  w  . ja v  a 2 s . c  o  m
using System.Globalization;
using System.Data.Entity.ModelConfiguration.Design.PluralizationServices;
using System;

public class Main{
        #endregion TryParseInt

       

       
        #region Methods
        /// <summary>
        /// Ellipses the specified STR.
        /// </summary>
        /// <param name="str">The STR.</param>
        /// <param name="length">The length.</param>
        /// <param name="ellipsisLength">Length of the ellipsis.</param>
        /// <returns></returns>
        public static string Ellipsis(this string str, int length, int ellipsisLength = 3)
        {
            if (str == null)
                return str;

            if (str.Length <= length)
                return str;

            return str.Substring(0, length - ellipsisLength).PadRight(length, '.');
        }
}

Related Tutorials