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