string f(string data)
{
StringBuilder sb = new StringBuilder();
int offset = 'A' - 'a';
if (!string.IsNullOrEmpty(data))
{
foreach (var item in data)
{
if (item >= '0' && item <= '9' || item >= 'a' && item <= 'z' || item >= 'A' && item <= 'Z')
{
var c = item;
if (item >= 'a' && item <= 'z')
{
c = (char)(item + offset);
}
if (item >= 'A' && item <= 'Z')
{
c = (char)(item - offset);
}
sb.Append(c);
}
}
}
return sb.ToString();
}
面試題,自己寫的。啦啦啦.