華為面試官給的題,由於大學四年的編程不到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;
}