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. breaking a string to substrings

breaking a string to substrings

Scheduled Pinned Locked Moved C#
question
5 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.
  • M Offline
    M Offline
    myinstincts
    wrote on last edited by
    #1

    i am having a string ,say"14p"....I want to take only the value 14 so that i could convert that to integer..how can i achieve this?

    M M 2 Replies Last reply
    0
    • M myinstincts

      i am having a string ,say"14p"....I want to take only the value 14 so that i could convert that to integer..how can i achieve this?

      M Offline
      M Offline
      myinstincts
      wrote on last edited by
      #2

      n i want to split that string on occurence of any alphabets

      P 1 Reply Last reply
      0
      • M myinstincts

        n i want to split that string on occurence of any alphabets

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

        hi, I did this using regular expressions. I wrote a method to split a string by alphabetic characters. 14p gives array of one item 14 14eur gives an array of one item 14 14eur14pp15p gives an array of 3 items 14, 14, and 15 http://pastebin.com/f55499ed[^]

        modified on Wednesday, December 30, 2009 2:56 AM

        C 1 Reply Last reply
        0
        • M myinstincts

          i am having a string ,say"14p"....I want to take only the value 14 so that i could convert that to integer..how can i achieve this?

          M Offline
          M Offline
          Md Marufuzzaman
          wrote on last edited by
          #4

          Assume that your input string like: Input: a1f2g3r46mj5kde6 Output:123456 I think at first you split it in to an array and pass each array item to a function for numeric validation. That.s It...:)

          Thanks Md. Marufuzzaman


          Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you. I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.

          1 Reply Last reply
          0
          • P petercrab

            hi, I did this using regular expressions. I wrote a method to split a string by alphabetic characters. 14p gives array of one item 14 14eur gives an array of one item 14 14eur14pp15p gives an array of 3 items 14, 14, and 15 http://pastebin.com/f55499ed[^]

            modified on Wednesday, December 30, 2009 2:56 AM

            C Offline
            C Offline
            coolestCoder
            wrote on last edited by
            #5

            how about this -

            public String[] Split(String alpha)
            {
            String str = alpha;
            List<String> returnVal = new List<String>();

                    Regex regexp = new Regex("\[0-9\]+");
                    MatchCollection matchColection = regexp.Matches(str);
                    for (int i = 0; i < matchColection.Count; i++)
                    {
                        returnVal.Add(matchColection\[i\].Value);
                    }
            
                    return returnVal.ToArray();
            
                }
            

            Modified Split function[^]


            "A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder


            coolestCoder

            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