TakeFirst

public static string TakeFirst(this string s, int num)
{
    if(string.IsNullOrEmpty(s))
        return s;

    return (s.Length < num ? s : s.Substring(0, num));
}
Example:
string someString = "Awesome";
string firstThree = "Awesome".TakeFirst(3);
//firstThree now is the string "Awe".

Description

Returns the first X characters from a string.

Details

Double click on the code to select all.

 

;