c# only take up to the first 5 characters of string code example Example: c# get first 5 characters of string string result = str.Substring(0,5);