Convert String into Pascal Case

This method is used for conversion of input string into pascal case



private string ConvertToPascal(string strFileName)
{
if (strFileName == null) throw new ArgumentNullException("strException", "Null is not a valid string!");
if (strFileName.Length == 0) return strFileName;
string[] strWords = strFileName.Split(' ');
for (int i = 0; i < strWords.Length; i++)
{
if (strWords[i].Length > 0)
{
string strWord = strWords[i];
char strFirstLetter = char.ToUpper(strWord[0]);
strWords[i] = strFirstLetter + strWord.Substring(1);
}
}
return string.Join(" ", strWords);
}


Comments

No responses found. Be the first to comment...