华为面试官给的题,由于大学四年的编程不到500行,当时就被鄙视了。。。
现思路如下:
1,判断是大写还是小写 ,这通过字符的比较即可得
2,对字符的ascci码加或减(‘a’- ‘A’= 32)实现大小写转化
private void button1_Click(object sender, System.EventArgs e)
{
string inputStr = textBox1.Text;
char[] outputStr = new char[inputStr.Length];
string s = string.Empty;
for(int i = 0; i < textBox1.Text.Length; i ++)
{
if(inputStr[i] >= 'a' && inputStr[i] <= 'z')
outputStr[i] = (char)(inputStr[i]- ('a' - 'A'),',',');
if(inputStr[i] >= 'A' && inputStr[i] <= 'Z')
outputStr[i] = (char)(inputStr[i] + ('a' - 'A'),',',');
}
for(int i = 0; i < outputStr.Length; i ++)
{
s = s + outputStr[i].ToString(,',',');
}
label1.Text = s;
}