public class CleanedName { // Clean Name // -------------------------------------------------- // Given a string, this will remove illegal characters so // it fits within Maya naming conventions public static string CleanName(string name) { // We have to strip out any illegal characters from the name // a-z A-Z 0-9 and _ are the only accepted characters StringBuilder cleanedName = new StringBuilder(); // Convert the name into an array of char char[] nameArray = name.ToCharArray(); // We will be moving forward through the name, // keeping only letters, numbers, and underscores. foreach (char character in nameArray) { if (char.IsLetterOrDigit(character)) cleanedName.Append(character); else if (character == '_') cleanedName.Append(character); } // Convert the stringbuilder into a string return cleanedName.ToString(); } }