Source/NFX/MiscUtils.cs
/// <summary>
/// Takes first X chars from a string. If string is null returns null. If string does not have enough
/// the function returns what the string has
/// </summary>
Takes first X chars from a string. If string is null returns null. If string does not have enough
the function returns what the string has
Takes first X chars from a string . If string is null returns null . If string does not have enough the function returns what the string has
public static string TakeFirstChars(this string str, int count, string ellipsis = null)
    {
      if (str==null) return null;
      if (str.Length<=count) return str;
      ellipsis = ellipsis ?? string.Empty;
      if (count > ellipsis.Length)
        count -= ellipsis.Length;
      else
        return ellipsis.Substring(0, count);
      return str.Substring(0, count) + ellipsis;
    }
public static string TakeFirstChars ( this string str , int count , string ellipsis = null ) { if ( str == null ) return null ; if ( str . Length <= count ) return str ; ellipsis = ellipsis ?? string . Empty ; if ( count > ellipsis . Length ) count -= ellipsis . Length ; else return ellipsis . Substring ( 0 , count ) ; return str . Substring ( 0 , count ) + ellipsis ; }
Takes first X chars from a string.
Takes first X chars from a string .
string
this
count
int
ellipsis
string