2个回答
展开全部
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;
}
试试这个
textBox2.Text = textBox1.Text.ToUpper(); //转换为 大写
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;
}
试试这个
textBox2.Text = textBox1.Text.ToUpper(); //转换为 大写
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |