如何将 23456 转换为字符串并显示为 "Two Three Four Five Six"?

How to Convert 23456 into string and it should display like "Two Three Four Five Six"?

我需要帮助来转换任何给定的数字,例如 TextBox 中的“0123456789”,以转换为 "Zero One Two Three Four Five Six Seven Eight Nine" 之类的字符串并在 VB.Net 中打印。

为什么不做一个读取到最后的函数,并且对于每个整数,用 table 作为 1 -> One 进行转换; 2 -> 两个等等 ?

喜欢

Dim something as somewhat control that can carry text
Dim converted as other somewhat control that also can carry text

for each char in something.text
if char = ("1") then
converted.text = converted.text & ("one")
elseif char = ("2")
converted.text = converted.text & ("two")
elseif
...

抱歉我的英语不好,希望你能从我的 a**

中看到一些快速、肮脏和混乱的想法

正如 Jimi 所建议的,您可以这样做

Dim wordsarray As String() = {"Zero", "One", "Two", " Three" , "Four", "Five", "Six", "Seven", "Eight", "Nine"}
Dim result As String = ""
For each c As Char In TextBox1.Text
  result &= wordsarray(Integer.Parse(c)) & " "
Next
'The string is now stored in the result variable and you can do something like this
Msgbox(result)

有了这个,你必须确保文本框的值只是整数

我的解决方案

Function NumberToText1(ByVal n As Integer) As String ' numeri da 0 a 9
    Dim arr() As String = {"Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven",
"Eight", "Nine"}
    Return arr(n) & " "
End Function

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim w As String = ""
    For Each s As String In TextBox1.Text
        w += NumberToText1(CInt(s))
    Next
    MessageBox.Show(w)
End Sub

0.02 美元

Private Function NumberDigitsToText(Num As Integer) As String
    Dim rv As String = ""
    Dim words() As String = {"Zero ", "One ", "Two ", "Three ", "Four ", "Five ", "Six ", "Seven ", "Eight ", "Nine "}

    rv = String.Join("", (From c In Num.ToString
                          Select words(Integer.Parse(c))))
    Return rv
End Function