Shorten String For Preview - CSharp System

CSharp examples for System:String Shorten

Description

Shorten String For Preview

Demo Code


using System.Xml.Linq;
using System.Web;
using System.Text.RegularExpressions;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;//from   w  w w  . j av  a 2 s.  c  om

public class Main{
        public static string ShortenStringForPreview(string one, string two, string three)
        {
            var result = string.Empty;
            var fullResult = string.Empty;
            if (!String.IsNullOrEmpty(one))
            {
                if (one.Length >= 30)
                {
                    result = one.Substring(0, 30) + "...";
                }
                else
                {
                    result = one;
                }
                fullResult = one;
            }
            else if (!String.IsNullOrEmpty(two))
            {
                if (two.Length >= 30)
                {
                    result = two.Substring(0, 30) + "...";
                }
                else
                {
                    result = two;
                }
                fullResult = two;
            }
            else if (!String.IsNullOrEmpty(three))
            {
                if (three.Length >= 30)
                {
                    result = three.Substring(0, 30) + "...";
                }
                else
                {
                    result = three;
                }
                fullResult = three;
            }
            return result.Replace("\n", "").StringNormalizer();
        }
        public static string StringNormalizer(this string s)
        {
            var st = new StringBuilder(s.RemoveDangerousChars().CorrectFarsiChars());
            return st.ToString();
        }
}

Related Tutorials