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. Help needed with string operation

Help needed with string operation

Scheduled Pinned Locked Moved C#
questionhelp
2 Posts 2 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.
  • H Offline
    H Offline
    hasanali00
    wrote on last edited by
    #1

    Hi I need a bit of help. I have this string: "10 > 8 > 99> 34" From this string, how can I extract all the numbers? Basically, when I receive the above string, I want to get every number out of it and do something with that number. Thanks

    W 1 Reply Last reply
    0
    • H hasanali00

      Hi I need a bit of help. I have this string: "10 > 8 > 99> 34" From this string, how can I extract all the numbers? Basically, when I receive the above string, I want to get every number out of it and do something with that number. Thanks

      W Offline
      W Offline
      Wjousts
      wrote on last edited by
      #2

      string[] numberstrings = mystring.split('>'); int[] numbers = new int[numberstrings.Length]; for (int i=0; i<numberstrings.Length; i++) { numbers[i] = int.Parse(numberstrings[i]); }
      You might want to make sure that all the strings that come out of the split really are numbers through so you should probably wrap the line in the for loop with a try/catch statement to be safe. -- modified at 10:52 Monday 5th June, 2006

      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