Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>public static string[] SplitArguments(string args) { char[] parmChars = args.ToCharArray(); bool inSingleQuote = false; bool inDoubleQuote = false; bool escaped = false; bool lastSplitted = false; bool justSplitted = false; bool lastQuoted = false; bool justQuoted = false; int i, j; for(i=0, j=0; i&lt;parmChars.Length; i++, j++) { parmChars[j] = parmChars[i]; if(!escaped) { if(parmChars[i] == '^') { escaped = true; j--; } else if(parmChars[i] == '"' &amp;&amp; !inSingleQuote) { inDoubleQuote = !inDoubleQuote; parmChars[j] = '\n'; justSplitted = true; justQuoted = true; } else if(parmChars[i] == '\'' &amp;&amp; !inDoubleQuote) { inSingleQuote = !inSingleQuote; parmChars[j] = '\n'; justSplitted = true; justQuoted = true; } else if(!inSingleQuote &amp;&amp; !inDoubleQuote &amp;&amp; parmChars[i] == ' ') { parmChars[j] = '\n'; justSplitted = true; } if(justSplitted &amp;&amp; lastSplitted &amp;&amp; (!lastQuoted || !justQuoted)) j--; lastSplitted = justSplitted; justSplitted = false; lastQuoted = justQuoted; justQuoted = false; } else { escaped = false; } } if(lastQuoted) j--; return (new string(parmChars, 0, j)).Split(new[] { '\n' }); } </code></pre> <p>based on <a href="https://stackoverflow.com/a/2132004/1377267">Vapour in the Alley</a>'s answer, this one also supports ^ escapes</p> <p>Examples:</p> <ul> <li>this is a test <ul> <li>this</li> <li>is</li> <li>a</li> <li>test</li> </ul></li> <li>this "is a" test <ul> <li>this</li> <li>is a</li> <li>test</li> </ul></li> <li>this ^"is a^" test <ul> <li>this</li> <li>"is</li> <li>a"</li> <li>test</li> </ul></li> <li>this "" "is a ^^ test" <ul> <li>this</li> <li> </li> <li>is a ^ test</li> </ul></li> </ul> <p>also supports multiple spaces (breaks args just one time per block of spaces)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload