如果我输入"1",如何打印字符串如果我输入"12",则打印“一个".如果我输入"123",则打印“一个二"然后打印“一二三" [英] how to print string, if i input "1" then print "One", if i input "12" then print "One Two", if i input "123" then print "One Two Three"
本文介绍了如果我输入"1",如何打印字符串如果我输入"12",则打印“一个".如果我输入"123",则打印“一个二"然后打印“一二三"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何打印字符串,如果我输入"1"然后打印一",如果我输入"12"然后打印一二",如果我输入"123"然后打印一二三"
how to print string, if i input "1" then print "One", if i input "12" then print "One Two", if i input "123" then print "One Two Three"
推荐答案
我不会给您完整的代码,但是:
I won''t give you the whole code, but:
string inp = "123";
foreach (char c in inp)
{
string word = "";
switch (c)
{
case '0': word = "zero "; break;
case '1': word = "one "; break;
...
}
Console.Write(word);
}
这是一种方法
创建一个枚举
Here is one approach
Create an enum
enum Number
{
zero,
one,
two,
three,
four,
five,
six,
seven,
eight,
nine,
}
从字符串中读取每个字符,并从枚举中获取其对应的文本
Read each character from the string and get its corresponding text from enum
string Text = "";
string value = "01234";
for (int i = 0; i < value.Length; i++)
{
Text += (Number)(int.Parse(value.Substring(i, 1))) + " ";
}
Console.WriteLine(Text);
嗨 试试这个:
Hi Try this:
int inNum = 0;
string inString = inNum.ToString();
string outText = "";
for (int i=0;i<instring.length;i++)>
{
string number=inString.Substring(i,1);
string oneWordOutput="";
switch(number)
{
case "1":
oneWordOutput = "One";
break;
case "2":
oneWordOutput = "Two";
break;
case "3":
oneWordOutput = "Three";
break;
case "4":
oneWordOutput = "Four";
break;
case "5":
oneWordOutput = "Five";
break;
case "6":
oneWordOutput = "Six";
break;
case "7":
oneWordOutput = "Seven";
break;
case "8":
oneWordOutput = "Eight";
break;
case "9":
oneWordOutput = "Nine";
break;
case "0":
oneWordOutput = "Zero";
break;
default:
break;
}
If(outText="")
{
outText = oneWordOutput;
}
else
{
outText = outText + " " + oneWordOutput;
}
}
雅克
Jacques
这篇关于如果我输入"1",如何打印字符串如果我输入"12",则打印“一个".如果我输入"123",则打印“一个二"然后打印“一二三"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文