right now in order for me to take a enum name and format it with spacing according to the capitalization of words.
I’m using
AIName = ObjectNames.NicifyVariableName(m_MobCharacter.ToString());
The issue with this is it requires UnityEditor.
so doing a windows build doesn’t work with this.
Is another way to format it like this?
Or anyone have a function that does this?
Here is something I quickly whipped up in an online compiler:
using System;
public class Test
{
public static void Main()
{
// Our string to add spaces to
string t = "ThisIsATest";
string result = "";
// Loop through our string
for(int i = 0; i < t.Length; i++)
{
// If this character is a capital and it is not the first character add a space.
// This is because we dont want a space before the word has even begun.
if(char.IsUpper(t[i]) == true && i != 0)
{
result += " ";
}
// Add the character to our new string
result += t[i];
}
Console.WriteLine(result);
// Prints "This Is A Test"
}
}
1 Like
Thanks man. I appreciate it.
Probably add char.length as a variable though
Actually I think I recently learned that csharp cached length checks so it doesn’t matter
1 Like