C#从键盘上输入一个小写字符,在屏幕上输出该字符以及它的大写字符和它的ASCII码。

求代码

string s = Console.ReadLine();
if (s.Length != 1)
{
Console.WriteLine("你输入字符长度不正确");
return;
}
if ("abcdefghijklmnopqrstuvwxyz".IndexOf(s) < 0)
{
Console.WriteLine("你输入的不是小写字母");
return;
}
Console.WriteLine("你输入的是" + s);
Console.WriteLine("对应的大写是" + s.ToUpper());
byte[] array = new byte[1]; //定义一组数组array
array = System.Text.Encoding.ASCII.GetBytes(s); //string转换的字母
int asciicode = (short)(array[0]);
string ASCII = Convert.ToString(asciicode); //将转换一的ASCII码转换成string型
Console.WriteLine(s + "的ASCII码是" + ASCII);
Console.ReadKey();追问

有没有简单一点的代码最好有点中文的简单一点的最好了谢谢

追答

留下QQ 我加你 收你做徒弟吧

追问

私信了

追答

Copy

温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-10-10
#include<stdio.h>
void main(){
char a;
printf("\n请输入一个字符");
scanf("%c",&a);
if((a>='a'&& a<='z')){
printf("\n ",a-32);
}}

/* printf("%c",a-32); /*小写字母减32为大写字母*/*/追问

我要的是c#的不是c的

第2个回答  2014-10-10
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{

class Program
{
static void Main(string[] args)
{

Console.WriteLine("Please input lower:");
string lower = Console.ReadLine();
string upper = lower.ToUpper();
System.Text.ASCIIEncoding asciiEncoding = new ASCIIEncoding();
int intAsciiCode = (int)asciiEncoding.GetBytes(lower)[0];
Console.WriteLine("Upper: " + upper);
Console.WriteLine("ASCII: " + intAsciiCode);
}
}
}追问

有没有简单一点的代码最好有点中文的简单一点的最好了谢谢

追答

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{

class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入小写字母 :");
string lower = Console.ReadLine();
Console.WriteLine("对应大写 : " + lower.ToUpper());
Console.WriteLine("对应ASCII: " + (int)System.Text.Encoding.ASCII.GetBytes(lower)[0]);
}
}
}

相似回答