Rate this:
See more:
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"
Posted 15-Nov-12 20:32pm
digimanus at 16-Nov-12 2:54am

read the string character by chraacter and via switch case translate number to word

Rate this:

## Solution 1

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);
}```
Pro Idiot at 16-Nov-12 3:21am

This is the whole code ;) even taken care of spacing as well ..
Rate this:

## Solution 5

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);
```
Rate this:

## Solution 3

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
Rate this:

## Solution 6

Hi

```int intVal = 12345;
Char[] charVal = intVal.ToString().ToCharArray();
string result = string.Empty;
for (int i = 0; i < charVal.Length; i++)
{
switch (charVal[i])
{
case'1':
result = result + " One";
break;
case '2':
result = result + " Two";
break;
case '3':
result = result + " Three";
break;
case '4':
result = result + " Four";
break;
case '5':
result = result + " Five";
break;
}
}```

Regards
Dominic
Rate this:

## Solution 7

Hi

How to convert a numeric value or currency to English words using C#[^]

Regards
Dominic
Rate this:

## Solution 2

use above code before that perform split operation.
Nelek at 16-Nov-12 4:01am

Please don't post solutions to add information, to ask something or to comment another user. - To add information to your message, you can use the widget "Improve question" at the bottom of your text. - To answer a user, you can use the widget "Have a question or comment?" (as I am doing right now with you) or the widget "reply" in another comment.
Rate this:

## Solution 4

but i want if i input "123" then print "one hundred and twenty-three"
digimanus at 16-Nov-12 3:29am

that is a change of question. You completely state something else as above in your question. Trolltime?
Nelek at 16-Nov-12 4:02am

Please don't post solutions to add information, to ask something or to comment another user. - To add information to your message, you can use the widget "Improve question" at the bottom of your text. - To answer a user, you can use the widget "Have a question or comment?" (as I am doing right now with you) or the widget "reply" in another comment.
Rate this:

## Solution 8

It's a very simple solution y you are treating it as very crucial thing just follow the instructions and do it.