Let´s s开发者_开发技巧ay I´ve got the following xml string:
<Item Name=\"$Resources:myresource,somestring;\"</Item>
Now I want to pick out all the occurrences of $Resource tags in it (there can be any number of them).
I actually wan´t to replace these resx strings with their corresponding values but that code I´ve already got.
The "problem" is that the code that is supposed to get these values for me requires that I pass in the name of the resource file (e.g. the part after $Resource. In this example it would be myresource) and the actual resource object (e.g. somestring).
Now I have been playing around with regular expression to accomplish this for me and what I really want is to put these two values into two different groups (because sometimes the "resource file" will be a default one, e.g. it can also look like $Resource:somestring).
Anyone got an idea of how to do that or can I perhaps use something in .NET that will do this for me, e.g. give me the classname (I think it´s the appropriate name for a resource file) in one property and the resource object in another one??
The RegEx is actually pretty simple:
(\$Resources\:(?<name>[^,;]+),(?<content>[^;]+);)|(\$Resources\:(?<content>[^;]+);)
For the following string it would return 3 results, where two results have the groups name
and content
and one result only has the group content
.
Sample data:
<Item Name=\"$Resources:somedefaultstring;$Resources:myresource,somestring;$Resources:myresource2,somestring2;$Resources:somedefaultstring;\"</Item>
UPDATE:
Fixed according to the comment.
精彩评论