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. How To Separate Number ?

How To Separate Number ?

Scheduled Pinned Locked Moved C#
helptutorialquestion
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.
  • P pakpatel

    If i have vriable string i; // i = 34245 (Whatever use put a number) If i want to separate the "34245"(by one digit)So what method should i use. i want to make a program where usere put any number and result come like 12345 one two three four five. Is thay anyone can help me with that ? -Thanks

    Peter

    C Offline
    C Offline
    Christian Graus
    wrote on last edited by
    #2

    A string is an array of chars. foreach(char c in "12345") will iterate over the numbers. If you have non numbers in your string, Char.IsDigit will tell you if it's a number.

    Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

    P 1 Reply Last reply
    0
    • C Christian Graus

      A string is an array of chars. foreach(char c in "12345") will iterate over the numbers. If you have non numbers in your string, Char.IsDigit will tell you if it's a number.

      Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      P Offline
      P Offline
      pakpatel
      wrote on last edited by
      #3

      in ouput only comes the value of last digit if out put is 12345 five it's loop through one two three four five but pirnt only five ? no one two three four is on screen only five... can you tell me how should i get the whole value ? 12345 one two three four five -Thanks

      Peter

      C 1 Reply Last reply
      0
      • P pakpatel

        in ouput only comes the value of last digit if out put is 12345 five it's loop through one two three four five but pirnt only five ? no one two three four is on screen only five... can you tell me how should i get the whole value ? 12345 one two three four five -Thanks

        Peter

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #4

        I have no idea where your code is broken, you've not posted it. foreach(char c in "12345") { switch(c) { case '1': // print 'one' // etc } } will most certainly work.

        Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

        P 1 Reply Last reply
        0
        • C Christian Graus

          I have no idea where your code is broken, you've not posted it. foreach(char c in "12345") { switch(c) { case '1': // print 'one' // etc } } will most certainly work.

          Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

          P Offline
          P Offline
          PIEBALDconsult
          wrote on last edited by
          #5

          Ah, but a Dictionary<char,string> would be so much more flexible and the teacher will be most impressed. ;P

          C V 2 Replies Last reply
          0
          • P PIEBALDconsult

            Ah, but a Dictionary<char,string> would be so much more flexible and the teacher will be most impressed. ;P

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #6

            Yeah, until the teacher asked him to explain the code....

            Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

            P 1 Reply Last reply
            0
            • C Christian Graus

              Yeah, until the teacher asked him to explain the code....

              Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

              P Offline
              P Offline
              PIEBALDconsult
              wrote on last edited by
              #7

              Oh, in that case maybe an enum.

              C 1 Reply Last reply
              0
              • P PIEBALDconsult

                Oh, in that case maybe an enum.

                C Offline
                C Offline
                Christian Graus
                wrote on last edited by
                #8

                How about just an array of strings and int.TryParse to get the index ?

                Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

                P 1 Reply Last reply
                0
                • C Christian Graus

                  How about just an array of strings and int.TryParse to get the index ?

                  Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

                  P Offline
                  P Offline
                  pakpatel
                  wrote on last edited by
                  #9

                  I try this method and it's work string[] spliter = fileName.Split(new char[]{'\\'}); -thanks for ur support

                  Peter

                  1 Reply Last reply
                  0
                  • P PIEBALDconsult

                    Ah, but a Dictionary<char,string> would be so much more flexible and the teacher will be most impressed. ;P

                    V Offline
                    V Offline
                    Vikram A Punathambekar
                    wrote on last edited by
                    #10

                    I seriously doubt it's homework help he's asking.

                    Cheers, Vikram.


                    Zeppelin's law: In any Soapbox discussion involving Stan Shannon, the probability of the term "leftist" or "Marxist" appearing approaches 1 monotonically. Harris' addendum: I think you meant "monotonously". Martin's second addendum: Jeffersonian... I think that should at least get a mention.

                    P 1 Reply Last reply
                    0
                    • V Vikram A Punathambekar

                      I seriously doubt it's homework help he's asking.

                      Cheers, Vikram.


                      Zeppelin's law: In any Soapbox discussion involving Stan Shannon, the probability of the term "leftist" or "Marxist" appearing approaches 1 monotonically. Harris' addendum: I think you meant "monotonously". Martin's second addendum: Jeffersonian... I think that should at least get a mention.

                      P Offline
                      P Offline
                      PIEBALDconsult
                      wrote on last edited by
                      #11

                      Oh, no, most assuredly not. :-D

                      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