需要帮助将数字转换为相关单词 [英] Need Help for Converting number into relavent word
本文介绍了需要帮助将数字转换为相关单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
输入12345之类的数字时,我只有一个文本框.label控件将显示以下单词
一二三四五
请帮助我
EG:
输入:5624
输出:五六二四
感谢和问候
Prabu T
Hi,
i Have one textbox when enter the number like 12345 .label control will display the following words
One Two Three Four Five
Please Help Me
EG:
Input:5624
Output:Five Six Two Four
Thanks And Regards
Prabu T
推荐答案
我的这两篇文章仅适合您.
1)将数字货币转换为单词(仅适用于印度货币)(已优化) [将数字货币转换为国际货币的单词-第二部分(优化) [ ^ ]
如果能帮到您,我会很高兴.
好吧,我再次得知您不希望使用货币
然后,您可以将简单的字符串数组放入
My These two article there only for you.
1)Convert Numeric Currency into Words (For INDIAN Currency Only) (Optimized)[^]
2)Convert Numeric Currency into Words for International Currency - Part - II (Optimized)[^]
I will be glad if it helps you.
Okey I again get to know that you don''t want it for currency
Then you could just put simple array of string like
string[] strarr = new string[]{"zero","one","two"};
现在从中相应地得到一个值.
就像您的电话号码是120一样,您可以像
一样获取
now get a value accordingly from that.
like if your number is 120 then you can fetch like
string input = "120"
string output = String.Empty;
foreach(char c in input)
{
output += strarr[Int32.TryParse(c)].ToString() + " ";
}
而且我认为您会获得必需的输出.
And I think you will get a required output.
又快又脏:
Quick and dirty:
private string NumberToWord(int n)
{
if ((n < 0) || (n > 9))
throw new ApplicationException("Invalid Argument");
switch(n)
{
case 0:
return "zero";
case 1:
return "one";
case 2:
return "two";
case 3:
return "three";
case 4:
return "four";
case 5:
return "five";
case 6:
return "six";
case 7:
return "seven";
case 8:
return "eight";
case 9:
return "nine";
}
return "";
}
private void button1_Click(object sender, EventArgs e)
{
string str = "124345"; //or TextBox.Text instead :)
label2.Text = "";
for (int n = 0; n < str.Length; n++ )
{
label2.Text += NumberToWord(Int32.Parse(str.Substring(n, 1))) + " ";
}
}
这确实是一项琐碎的任务:使用您喜欢的语言(您未指定):
1.创建字符串数组{"One","Two",...,"Nine"}
2.使用数字含义作为数组的索引迭代输入字符串字符.
:)
It is really a trivial task: in your favourite language (you didn''t specify it):
1. Create the array of strings {"One", "Two", ..., "Nine"}
2. Iterate on the input string characters using their numeric meaning as indices for the array.
:)
这篇关于需要帮助将数字转换为相关单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文