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. .NET (Core and Framework)
  4. String index

String index

Scheduled Pinned Locked Moved .NET (Core and Framework)
regexdatabasehelptutorialquestion
4 Posts 2 Posters 1 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.
  • K Offline
    K Offline
    kalkwarf
    wrote on last edited by
    #1

    I am enumerating through a collection where the index is a string. I would like to get my hands on that string. I am working with regular expression named groups, but the issue is the same for any collection indexed with strings. An example: Regex regEx = new Regex(@"^(?<name>\w+):(?<value>\w+)"); Match match = regEx.Match("abc:123"); GroupCollection groups = match.Groups; Console.WriteLine(groups["name"]); Console.WriteLine(groups["value"]); (Note that the sad face emoticon in the first line should be a colon followed by a left parenthesis. I could not turn this off.) The above writes the following to the Console: abc 123 I would like to also write the index so the output looks like: name = abc value = 123 Ideally, I would like to use a foreach to print all indexes and values in the collection. This would look something like: foreach (Group group in match.Groups) { Console.WriteLine(??? + " = " + group.Value); } I cannot figure out what "???" should be. Thanks.

    P 1 Reply Last reply
    0
    • K kalkwarf

      I am enumerating through a collection where the index is a string. I would like to get my hands on that string. I am working with regular expression named groups, but the issue is the same for any collection indexed with strings. An example: Regex regEx = new Regex(@"^(?<name>\w+):(?<value>\w+)"); Match match = regEx.Match("abc:123"); GroupCollection groups = match.Groups; Console.WriteLine(groups["name"]); Console.WriteLine(groups["value"]); (Note that the sad face emoticon in the first line should be a colon followed by a left parenthesis. I could not turn this off.) The above writes the following to the Console: abc 123 I would like to also write the index so the output looks like: name = abc value = 123 Ideally, I would like to use a foreach to print all indexes and values in the collection. This would look something like: foreach (Group group in match.Groups) { Console.WriteLine(??? + " = " + group.Value); } I cannot figure out what "???" should be. Thanks.

      P Offline
      P Offline
      Paul Conrad
      wrote on last edited by
      #2

      I looked into this and no real solution. Have you found a way to do this?

      "I guess it's what separates the professionals from the drag and drop, girly wirly, namby pamby, wishy washy, can't code for crap types." - Pete O'Hanlon

      K 1 Reply Last reply
      0
      • P Paul Conrad

        I looked into this and no real solution. Have you found a way to do this?

        "I guess it's what separates the professionals from the drag and drop, girly wirly, namby pamby, wishy washy, can't code for crap types." - Pete O'Hanlon

        K Offline
        K Offline
        kalkwarf
        wrote on last edited by
        #3

        No, I have not found a solution. I suspect it is buried in the container classes or iterators some place, but I haven't had time to look. It wasn't a high-priority issue for me, so I am currently doing without.

        P 1 Reply Last reply
        0
        • K kalkwarf

          No, I have not found a solution. I suspect it is buried in the container classes or iterators some place, but I haven't had time to look. It wasn't a high-priority issue for me, so I am currently doing without.

          P Offline
          P Offline
          Paul Conrad
          wrote on last edited by
          #4

          kalkwarf wrote:

          I suspect it is buried in the container classes or iterators some place

          I would think so. For fun I am going to dig around at this and let you know if I run across anything :-D

          "I guess it's what separates the professionals from the drag and drop, girly wirly, namby pamby, wishy washy, can't code for crap types." - Pete O'Hanlon

          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