I have read this question to get first char of the string. Is there a way to get the first n number of characters from a string in C#?
Kindly try this code when str is less than 5.
string strModified = str.Substring(0,str.Length>5?5:str.Length);