c# - How to split this string on commas, but only if it meets this criteria? -


(This is very much like my previous question, but I realized that I was trying to solve the wrong problem )

I am creating some jQuery, and I am trying to parse the selectors. So, something like this has been given:

  how can one [http: //www.webd.url/hascommerce]], strong  

I split it into

  [a href = "http: //weird.url/hascommar"] strong  

?

It needs to be split on a comma, but only if it is not in quote, or in a feature.


Modified version of the maximum solution:

  Fixed IEnumerable & lt; String & gt; SplitSelectors (string str) {int openBrackets = 0; Int lastIndex = 0; For (int i = 0; i & lt; str.Length; ++ i) {switch (str [i]) {case '[': openBrackets ++; break; Case ']': OpenBrake-; break; Case ',': if (openbracket == 0) {yield returns str.Substring (final index, i - final index); Previous index = I + 1; }                     break; }} Yield returns str.Substring (lastIndex); }  

I am ignoring quotes, because I am not thinkers , they should be out of the specialty selector anyway. I'm trying to imitate jQuery specs, but I'm pretty sure what they are doing in this scenario.

  constant list & lt; String & gt; SplitBicaka (string str) {bull quoted = false; Bool attr = false; Int start = 0; Var result = new list & lt; String & gt; (); For (int i = 0; i & lt; str.Length; ++ i) {switch (str [i]) {case '[': if (! Quoted) attr = true; break; Case ']': if (! Quoted) attr = false; break; Case '\' ': if (! Etr) quoted =! Quoted; break; case', ': if (quoted & amp;! Etr) {result.ed (straw .Substring (start, i - start)); Start = i + 1;} break;}} If (start & lt; str.Length) result. Add (straw .Substring (start)); Return result;}  

Comments