split a string using a open and close tag
I wish to known if exist a clean way to split a string using different tags for opening and ending.
For example:
<&field1&>outside<&field2&>
using the fun开发者_StackOverflowction split:
string[] dd={"<&","&>"}; string[] b1 = a1.Split(dd,StringSplitOptions.None);
it show me:
- 0:
- 1:field1
- 2:outside
- 3:field2
- 4:
(that it is that i want to do). but also
<&field1<&outside<&field2<&
show the same.
@"\G<&(?<code>.*?)&>"
The TemplateParser in the AspCodeRegex class in System.Web.RegularExpressions uses something similar to this
(answer via @rexm)
You should use a regular expression to do this. After a quick play I came up with this which seems to match the entries within the <& &>
delimiters, but you get the idea:
<&([^&]*)&>
See Regular Expression Examples for some more examples and also the code you need to run your regex.
精彩评论