编程问题,考试中!急!在线等!好的话再加分!

来源:百度知道 编辑:UC知道 时间:2024/09/23 05:32:09
设计表单form1,表单中有命令按钮command1和两个文本框text1及text2,在text1中输入字
符串"Why SOA has emerged as the dominant approach to enterprise integration", 单击
命令按钮计算该字符串偶数位置中每个字符的ASCII码值的和,即h、空格、O等,并将结果
显示在text2框中。注意:输入字符串必须严格与题目中给出的字符串完全相同,即长度、大小
写、空格数等必须相同。

假设textBox1的Text为:Why SOA has emerged as the dominant approach to enterprise integration

使用C#代码编写。

最终TextBox2的Text输出结果为3265

byte[] ascb = System.Text.Encoding.ASCII.GetBytes(textBox1.Text);
int res = 0;

for (int i = 1; i < ascb.Length; i += 2)
{
int value = ascb[i];
res += value;
}

textBox2.Text = res.ToString();