I'm creating my own game and for some statistics I need to get the names of specific objects. The problem was that I had them declared like "SmallFireBall" but I wanted them to appear like"Small Fire Ball" because that's something the user is able to see, so I decided to create my own extension method to help me out:
public static string SplitOnCapitalLetters(this string inputString)
{
List<char> cleanString = inputString.ToList();
for (int i = 1; i < cleanString.Count; i++)
{
if (char.IsUpper(cleanString[i]))
{
char[] temp = new char[cleanString.Count - i];
for (int j = 0; j < temp.Length; j++)
{
temp[j] = cleanString[j + i];
}
cleanString[i] = ' ';
cleanString.Add(' ');
int index = 0;
for (int j = i + 1; j < cleanString.Count; j++)
{
cleanString[j] = temp[index];
index++;
}
i++;
}
}
return new string(cleanString.ToArray());
}
However, I'm not quite confident about it. It seems quite big and maybe a little bit ugly, so please address any performance or code style issues.