tags:

views:

64

answers:

2

Hi there:

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 function split:

        string[] dd={"<&","&>"};
        string[] b1 = a1.Split(dd,StringSplitOptions.None);

it show me:

  1. 0:
  2. 1:field1
  3. 2:outside
  4. 3:field2
  5. 4:

(that it is that i want to do). but also

<&field1<&outside<&field2<&

show the same.

+1  A: 

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.

GraemeF
+1  A: 
@"\G<&(?<code>.*?)&>"

The TemplateParser in the AspCodeRegex class in System.Web.RegularExpressions uses something similar to this
(answer via @rexm)

Chris Ballance