我需要从用户那里获取一个输入,将所有字符转换为十进制值并显示为一个没有空格的字符串,然后将其转换为字符串并显示它,然后取数字字符串并转回原始字符串。
A.“Hello World” - 字符串
B.“72101108108111 87111114108100” - 字符串
C.“7210110810811187111114108100”(已处理并显示) - int
D。“72101108108111 87111114108100” - 字符串
E。“Hello World” - 字符串
我到了这个阶段:
string input = Console.ReadLine();
byte[] array = Encoding.ASCII.GetBytes(input);
它并不多,但是我第一次尝试创建一个程序。
答案 0 :(得分:0)
这是一个使用十进制的例子。但你也可以使用System.Numerics.BigInteger及其ToString和Parse函数来获得更大的数字
http://msdn.microsoft.com/en-us/library/system.numerics.biginteger(v=vs.110).aspx
using System;
namespace big_number
{
class Program
{
static void Main(string[] args)
{
decimal d = 0;
begining:
try {d = Convert.ToDecimal(Console.ReadLine()); }//<------ HERE IT IS!!!
catch (Exception EX)// look up what exceptions you want to catch
{
Console.WriteLine("try again\r\n\n" + EX.Message);//display error (if you want)
d = 0;//just incase
goto begining; // do not run this code outside of debugger you may get caught in inifinite loop
}
//and back again
string s = "" + d;
Console.WriteLine(s);//we could just pass d
Console.ReadLine();
}
}
}