Squeaky Clean

avatar

using System;
using System.Reflection;
using System.Text;

public static class Identifier
{
public static string Clean(string identifier)
{
bool lastWasHyphen = false;
StringBuilder sb = new StringBuilder();
foreach(char c in identifier)
{
if(c == ' ')
{
sb.Append('_');
}
else if (char.IsControl(c))
{
sb.Append("CTRL");
}
else if (c == '-')
{
lastWasHyphen=true;
}
else if (Char.IsLetter(c) && ((c < '\u03ac') || (c > '\u03ce')))
{
if(lastWasHyphen)
{
char add = char.ToUpper(c);
sb.Append(add);
lastWasHyphen = false;
}
else sb.Append(c);
}
}
return sb.ToString();

}

}



0
0
0.000
0 comments