Shorten Text String - CSharp System

CSharp examples for System:String SubString

Description

Shorten Text String

Demo Code


using System.Web;
using System.Linq;
using System.Collections.Generic;
using System;/*ww w .j  ava  2  s .  c  o  m*/

public class Main{
        public static String ShortenText(String text, int maxLength)
        {
            String shortText = text;
            if (text != null && text.Length > maxLength)
                shortText = text.Substring(0, maxLength - 3) + "...";

            return shortText;
        }
}

Related Tutorials