Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Digit To text Converter [modified]

Digit To text Converter [modified]

Scheduled Pinned Locked Moved C#
helptutorial
11 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Syed Shahid Hussain
    wrote on last edited by
    #1

    I want the functionality of converting digits into text. Any one give me code example or an article about that. Example: 209 Two Hundred and Nine thanks "and Nader where are u i need u'r help" -- modified at 14:42 Friday 8th September, 2006

    Syed Shahid Hussain

    L N A 3 Replies Last reply
    0
    • S Syed Shahid Hussain

      I want the functionality of converting digits into text. Any one give me code example or an article about that. Example: 209 Two Hundred and Nine thanks "and Nader where are u i need u'r help" -- modified at 14:42 Friday 8th September, 2006

      Syed Shahid Hussain

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      Search this messageboard for 'eleventh' and'twelveth', there is a nice switch statement to deal with that, the rest will be easy.

      **

      xacc.ide-0.2.0.57 - now with C# 2.0 parser and seamless VS2005 solution support!

      **

      S 2 Replies Last reply
      0
      • L leppie

        Search this messageboard for 'eleventh' and'twelveth', there is a nice switch statement to deal with that, the rest will be easy.

        **

        xacc.ide-0.2.0.57 - now with C# 2.0 parser and seamless VS2005 solution support!

        **

        S Offline
        S Offline
        Syed Shahid Hussain
        wrote on last edited by
        #3

        Please give me some more detail or link to that article. Thanks

        Syed Shahid Hussain

        1 Reply Last reply
        0
        • L leppie

          Search this messageboard for 'eleventh' and'twelveth', there is a nice switch statement to deal with that, the rest will be easy.

          **

          xacc.ide-0.2.0.57 - now with C# 2.0 parser and seamless VS2005 solution support!

          **

          S Offline
          S Offline
          Syed Shahid Hussain
          wrote on last edited by
          #4

          tell me more friend. I am waiting.:( Please :((

          leppie wrote:

          Search this messageboard for 'eleventh' and'twelveth'

          What do you mean by that :^) Thanks

          Syed Shahid Hussain

          N 1 Reply Last reply
          0
          • S Syed Shahid Hussain

            tell me more friend. I am waiting.:( Please :((

            leppie wrote:

            Search this messageboard for 'eleventh' and'twelveth'

            What do you mean by that :^) Thanks

            Syed Shahid Hussain

            N Offline
            N Offline
            Nader Elshehabi
            wrote on last edited by
            #5

            Hello friend:)

            Syed Shahid Hussain wrote:

            I am waiting.

            No need. I'm working on it, and I'll post the code when I'm finished. Already half the way.

            Regards:rose:

            1 Reply Last reply
            0
            • S Syed Shahid Hussain

              I want the functionality of converting digits into text. Any one give me code example or an article about that. Example: 209 Two Hundred and Nine thanks "and Nader where are u i need u'r help" -- modified at 14:42 Friday 8th September, 2006

              Syed Shahid Hussain

              N Offline
              N Offline
              Nader Elshehabi
              wrote on last edited by
              #6

              Hello friend. Here is your code. I hope you like it;). 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));
              
              S 1 Reply Last reply
              0
              • N Nader Elshehabi

                Hello friend. Here is your code. I hope you like it;). 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));
                
                S Offline
                S Offline
                Syed Shahid Hussain
                wrote on last edited by
                #7

                Hi So so thanks. I am so happy that you has given me the code and spend your time on me. I'll use it and send u feedback. Thank you very much. (I cant imagine that some people are kind enough that they spend their precious time for others. I really appreciate you. I dont have words to thank U. Its my heart sound. By heart thanks alot. And dont mind if u dont like my talks. I am a simple boy and dont let any thing close in my heart, I say it at the spot.) God Bless You. Keep messaging, Your friend :rose:

                Syed Shahid Hussain

                N 1 Reply Last reply
                0
                • S Syed Shahid Hussain

                  Hi So so thanks. I am so happy that you has given me the code and spend your time on me. I'll use it and send u feedback. Thank you very much. (I cant imagine that some people are kind enough that they spend their precious time for others. I really appreciate you. I dont have words to thank U. Its my heart sound. By heart thanks alot. And dont mind if u dont like my talks. I am a simple boy and dont let any thing close in my heart, I say it at the spot.) God Bless You. Keep messaging, Your friend :rose:

                  Syed Shahid Hussain

                  N Offline
                  N Offline
                  Nader Elshehabi
                  wrote on last edited by
                  #8

                  Hello I'm always happy to help you:-D. See you soon on the forum.

                  Regards:rose:

                  S 1 Reply Last reply
                  0
                  • S Syed Shahid Hussain

                    I want the functionality of converting digits into text. Any one give me code example or an article about that. Example: 209 Two Hundred and Nine thanks "and Nader where are u i need u'r help" -- modified at 14:42 Friday 8th September, 2006

                    Syed Shahid Hussain

                    A Offline
                    A Offline
                    Arjun Mjolnir Bahree
                    wrote on last edited by
                    #9

                    Well a switch is a manual and less elegant way of doing this. A preferred way is having all the digit equivalents in a string table, and then having the conjuntion operators in another one, and a mapping list for mapping the info. I will try to post some code on it, using the neural approach that i did 6 years back.

                    Excelsior Arjun Bahree "By The Might of Mjolnir" I Came! I Coded! I Conquered!

                    S 1 Reply Last reply
                    0
                    • N Nader Elshehabi

                      Hello I'm always happy to help you:-D. See you soon on the forum.

                      Regards:rose:

                      S Offline
                      S Offline
                      Syed Shahid Hussain
                      wrote on last edited by
                      #10

                      Thanks friend, Your code is so logical and it took my two hrs. for understanding it. How your made the logic in just 35 min. You are a true programmer. The code meet all my requirements and I'll use it in my Data Base program "as it is" without any changing. So thanks and so nice of you. God Bless You "If u read this plz send me your e-mail address." Bye

                      Syed Shahid Hussain

                      1 Reply Last reply
                      0
                      • A Arjun Mjolnir Bahree

                        Well a switch is a manual and less elegant way of doing this. A preferred way is having all the digit equivalents in a string table, and then having the conjuntion operators in another one, and a mapping list for mapping the info. I will try to post some code on it, using the neural approach that i did 6 years back.

                        Excelsior Arjun Bahree "By The Might of Mjolnir" I Came! I Coded! I Conquered!

                        S Offline
                        S Offline
                        Syed Shahid Hussain
                        wrote on last edited by
                        #11

                        If you find code send me.

                        Syed Shahid Hussain

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups