Advertisement
Da_Gamer

Cleaned Name (Short 2)

Jan 8th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.93 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(name.Length);
  13.  
  14.             // We will be moving forward through the name,
  15.             // keeping only letters, numbers, and underscores.
  16.             foreach (char character in name)
  17.             {
  18.                 if (char.IsLetterOrDigit(character) || character == '_') cleanedName.Append(character);
  19.             }
  20.  
  21.  
  22.             // Convert the stringbuilder into a string
  23.             return cleanedName.ToString();
  24.         }
  25.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement