Strings
String extension truncate text
Truncates text to the given length. This is an extension method version of it.
public static string Truncate(string s, int max)
{
if (s.Length > max)
{
return s.Substring(0, max);
}
return s;
}
First char uppercase
This will change the first letter in a string (word or whole text) to upper case.
public static string UppercaseFirst(string s)
{
if (string.IsNullOrEmpty(s))
{
return string.Empty;
}
char[] a = s.ToCharArray();
a[0] = char.ToUpper(a[0]);
return new string(a);
}
Published: 2016-08-25