Individual Num To Text - CSharp System

CSharp examples for System:String Number

Description

Individual Num To Text

Demo Code


using System.Text.RegularExpressions;
using System.Text;
using System.Globalization;
using System.Collections.Generic;
using System;//from   ww  w . j  av a 2  s.  c o  m

public class Main{
        public static string IndividualNumToText(string t)
        {
            string[] split = t.Split(new Char[] { ' ' });
            List<string> newString = new List<string>();
            List<string> charList = new List<string>();
            foreach (string s in split)
            {
                try
                {
                    int n = Convert.ToInt16(s);
                    foreach (char c1 in s)
                    {
                        string cString = Convert.ToString(c1);
                        charList.Add(cString);
                    }
                    foreach (string c in charList)
                    {
                        if (c == "0")
                        {
                            newString.Add("zero");
                        }
                        if (c == "1")
                        {
                            newString.Add("one");
                        }
                        if (c == "2")
                        {
                            newString.Add("two");
                        }
                        if (c == "3")
                        {
                            newString.Add("three");
                        }
                        if (c == "4")
                        {
                            newString.Add("four");
                        }
                        if (c == "5")
                        {
                            newString.Add("five");
                        }
                        if (c == "6")
                        {
                            newString.Add("six");
                        }
                        if (c == "7")
                        {
                            newString.Add("seven");
                        }
                        if (c == "8")
                        {
                            newString.Add("eight");
                        }
                        if (c == "9")
                        {
                            newString.Add("nine");
                        }
                    }
                }
                catch
                {
                    newString.Add(s);
                }
            }
            StringBuilder sb = new StringBuilder();
            foreach (string t2 in newString)
            {
                sb.Append(t2 + " ");
            }
            return sb.ToString();
        }
}

Related Tutorials