Advertisement
Da_Gamer

Cleaned Name (Short 1)

Jan 8th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.08 KB | None | 0 0
  1.     public class CleanedName
  2.     {
  3.         // Clean Name
  4.         // --------------------------------------------------
  5.         // Given a string, this will remove illegal characters so
  6.         // it fits within Maya naming conventions
  7.         public static string CleanName(string name)
  8.         {
  9.             // We have to strip out any illegal characters from the name
  10.             // a-z A-Z 0-9 and _ are the only accepted characters
  11.  
  12.             StringBuilder cleanedName = new StringBuilder();
  13.  
  14.             // Convert the name into an array of char
  15.             char[] nameArray = name.ToCharArray();
  16.  
  17.             // We will be moving forward through the name,
  18.             // keeping only letters, numbers, and underscores.
  19.             foreach (char character in nameArray)
  20.             {
  21.                 if (char.IsLetterOrDigit(character)) cleanedName.Append(character);
  22.                 else if (character == '_') cleanedName.Append(character);
  23.             }
  24.  
  25.  
  26.             // Convert the stringbuilder into a string
  27.             return cleanedName.ToString();
  28.         }
  29.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement