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. String Parsing

String Parsing

Scheduled Pinned Locked Moved C#
jsonquestion
4 Posts 3 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
    mark_w_
    wrote on last edited by
    #1

    Not sure if this is the correct forum, but here goes I have a string eg string myString = "Setting17=50"; Now i want to get a substring from it by specifying 2 strings (start and end), ie i specify "Setting" and "=" and it returns 17. Can i do this with regular expressions? (if so any pointers would be great), or do i have to do string manipulation? (ie get the right of "settings" and then the left of "=") Regards Mark

    G B M 3 Replies Last reply
    0
    • M mark_w_

      Not sure if this is the correct forum, but here goes I have a string eg string myString = "Setting17=50"; Now i want to get a substring from it by specifying 2 strings (start and end), ie i specify "Setting" and "=" and it returns 17. Can i do this with regular expressions? (if so any pointers would be great), or do i have to do string manipulation? (ie get the right of "settings" and then the left of "=") Regards Mark

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      You can create a pattern from starting and ending strings: string start = "Setting"; string ending = "="; string pattern = Regex.Escape(start) + "([\w\W]*)" + Regex.Escape(ending);

      Despite everything, the person most likely to be fooling you next is yourself.

      1 Reply Last reply
      0
      • M mark_w_

        Not sure if this is the correct forum, but here goes I have a string eg string myString = "Setting17=50"; Now i want to get a substring from it by specifying 2 strings (start and end), ie i specify "Setting" and "=" and it returns 17. Can i do this with regular expressions? (if so any pointers would be great), or do i have to do string manipulation? (ie get the right of "settings" and then the left of "=") Regards Mark

        B Offline
        B Offline
        benjymous
        wrote on last edited by
        #3

        You could also use Split string splitParts[] = myString.split('='); splitParts[0] will be "Setting17" splitParts[1] will be "50"

        Help me! I'm turning into a grapefruit! Buzzwords!

        1 Reply Last reply
        0
        • M mark_w_

          Not sure if this is the correct forum, but here goes I have a string eg string myString = "Setting17=50"; Now i want to get a substring from it by specifying 2 strings (start and end), ie i specify "Setting" and "=" and it returns 17. Can i do this with regular expressions? (if so any pointers would be great), or do i have to do string manipulation? (ie get the right of "settings" and then the left of "=") Regards Mark

          M Offline
          M Offline
          mark_w_
          wrote on last edited by
          #4

          Thanks Guys, got it all sorted

          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