Click here to Skip to main content
16,004,887 members
Home / Discussions / C#
   

C#

 
Questionpotentially dangerous !!! Pin
Tamimi - Code29-Nov-06 20:58
Tamimi - Code29-Nov-06 20:58 
AnswerRe: potentially dangerous !!! Pin
Guffa30-Nov-06 0:17
Guffa30-Nov-06 0:17 
QuestionXmlDocument - Browser View in Form Pin
h@s@n29-Nov-06 20:35
h@s@n29-Nov-06 20:35 
AnswerRe: XmlDocument - Browser View in Form Pin
Nader Elshehabi29-Nov-06 22:39
Nader Elshehabi29-Nov-06 22:39 
GeneralRe: XmlDocument - Browser View in Form Pin
h@s@n29-Nov-06 23:00
h@s@n29-Nov-06 23:00 
GeneralRe: XmlDocument - Browser View in Form Pin
Nader Elshehabi30-Nov-06 1:06
Nader Elshehabi30-Nov-06 1:06 
QuestionNumber to words utility Pin
Ramesh.V29-Nov-06 20:33
Ramesh.V29-Nov-06 20:33 
AnswerRe: Number to words utility Pin
Nader Elshehabi29-Nov-06 22:47
Nader Elshehabi29-Nov-06 22:47 
I guess this is your lucky day.;) I made one just few months ago. Here is the code.

It consists of 3 methods. You call the ToLiteral() method and supply it with the string you want to parse. It will subsequently call the other two methods to retreive the literals and the segments names. Forgive me for the poor comment -never been good in commenting-. I included a button click even handler to show you how to test for output and how to use the ToLiteral() method.

private void TestButton_Click(object sender, EventArgs e)
    {
        //Random numbers in a MessageBox to test output
        MessageBox.Show("4\n" + ToLiterals("4"));
        MessageBox.Show("57\n" + ToLiterals("57"));
        MessageBox.Show("209\n" + ToLiterals("209"));
        MessageBox.Show("8734\n" + ToLiterals("8734"));
        MessageBox.Show("24567\n" + ToLiterals("24567"));
        MessageBox.Show("973654\n" + ToLiterals("973654"));
        MessageBox.Show("2315736\n" + ToLiterals("2315736"));
        MessageBox.Show("27065154\n" + ToLiterals("27065154"));
        MessageBox.Show("827464876\n" + ToLiterals("827464876"));
        MessageBox.Show("1675376283\n" + ToLiterals("1675376283"));
    }

    private string ToLiterals(string Input)
    {
        String Output = "";
        while (Input.Length > 0)
        {
            if (Input[0] == '0')//Ignore zeros
            {
                Input = Input.Remove(0, 1);
                Output += "And ";
                continue;
            }
            if (Input.Length % 3 != 2)
            {
                // We are at the Xs if our number is XYX,XYX,XYX
                // Either first, or third position in each segment.
                Output += ConvertChar(Input[0].ToString());
                if (Input.Length % 3 == 0 && Input.Length > 2) //third position in a segment
                    Output += "Hundred ";
                else
                    Output += GetSegment(Input.Length / 3); //first position
                    Input = Input.Remove(0, 1);
                continue;
            }
            else
            {
                //We are talking about first and second positions togerther :YXX,YXX,YXX
                if (Input[0] == '1') //Is it Xteen? ie. 11-19
                {
                    Output += ConvertChar(Input.Substring(0, 2));

                }
                else //Or above 19?
                {
                    Output += ConvertChar(Input[0] + "0");
                    Output += ConvertChar(Input[1].ToString());
                }
                Output += GetSegment(Input.Length / 3);
                Input = Input.Remove(0, 2);
            }
        }
        return Output;
    }

    private string GetSegment(int seg)
    {
        switch (seg)
        {
            case 1: { return "Thousand "; }
            case 2: { return "Million "; }
            case 3: { return "Billion "; }
            case 4: { return "Trillion "; }
            default: { return ""; }
                //The list can grow
        }
    }

    private string ConvertChar(string ToConvert)
    {
        switch (ToConvert)
        {
            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 "; }
            case "10": { return "Ten "; }
            case "11": { return "Eleven "; }
            case "12": { return "Twelve "; }
            case "13": { return "Thirteen "; }
            case "14": { return "Fourteen "; }
            case "15": { return "Fifteen "; }
            case "16": { return "Sixteen "; }
            case "17": { return "Seventeen "; }
            case "18": { return "Eighteen "; }
            case "19": { return "Nineteen "; }
            case "20": { return "Twenty "; }
            case "30": { return "Thirty "; }
            case "40": { return "Fourty "; }
            case "50": { return "Fifty "; }
            case "60": { return "Sixty "; }
            case "70": { return "Seventy "; }
            case "80": { return "Eighty "; }
            case "90": { return "Ninety "; }
            default: { return ""; }
        }
    }


RegardsRose | [Rose]

QuestionNeed to use REGEX Pin
M Riaz Bashir29-Nov-06 19:37
M Riaz Bashir29-Nov-06 19:37 
AnswerRe: Need to use REGEX Pin
Coding C#29-Nov-06 19:53
Coding C#29-Nov-06 19:53 
AnswerRe: Need to use REGEX Pin
quiteSmart29-Nov-06 19:57
quiteSmart29-Nov-06 19:57 
AnswerRe: Need to use REGEX Pin
Bassam Saoud29-Nov-06 20:02
Bassam Saoud29-Nov-06 20:02 
Questiondata grid Pin
kiranbabu29-Nov-06 19:35
kiranbabu29-Nov-06 19:35 
AnswerRe: data grid Pin
Nader Elshehabi29-Nov-06 22:49
Nader Elshehabi29-Nov-06 22:49 
AnswerRe: data grid Pin
ednrgc30-Nov-06 6:30
ednrgc30-Nov-06 6:30 
QuestionHow to get file path from save file dialogue box Pin
prakash_21029-Nov-06 19:27
prakash_21029-Nov-06 19:27 
AnswerRe: How to get file path from save file dialogue box Pin
Eduard Keilholz29-Nov-06 20:59
Eduard Keilholz29-Nov-06 20:59 
QuestionDirectoryInfo.GetFiles question Pin
coolestCoder29-Nov-06 18:46
coolestCoder29-Nov-06 18:46 
AnswerRe: DirectoryInfo.GetFiles question Pin
Scott Dorman29-Nov-06 18:51
professionalScott Dorman29-Nov-06 18:51 
QuestionNeed Help--Required permissions cannot be acquired. Pin
Jay Khanpara29-Nov-06 18:38
Jay Khanpara29-Nov-06 18:38 
QuestionChecking File in use before copy Pin
coolestCoder29-Nov-06 18:34
coolestCoder29-Nov-06 18:34 
AnswerRe: Checking File in use before copy Pin
Martin#29-Nov-06 20:52
Martin#29-Nov-06 20:52 
QuestionLocal Variable and "global" with same name Pin
Dwayner7929-Nov-06 16:54
Dwayner7929-Nov-06 16:54 
AnswerRe: Local Variable and "global" with same name Pin
Scott Dorman29-Nov-06 17:00
professionalScott Dorman29-Nov-06 17:00 
GeneralRe: Local Variable and "global" with same name Pin
Dwayner7929-Nov-06 18:19
Dwayner7929-Nov-06 18:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.