Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can first store your tokens in dynamic size component like <code>List</code>. To fill such list with your tokens you need to iterate over each character in your sentence and if it is not <code>,</code> that is inside quote then add it to tokenBuilder, but if that comma is outside quote then add current value of tokenBuilder to your tokenList. Here is example code. </p> <pre><code>String line = "\"start \\\"title\\\" end\", 10, 20, \"text\""; List&lt;String&gt; tokens = new ArrayList&lt;&gt;(); StringBuilder tokenBuilder = new StringBuilder(); boolean insideQuote = false; char ch, prev = ' '; for (int i = 0; i &lt; line.length(); i++) { ch = line.charAt(i); if (ch == '"' &amp;&amp; prev != '\\') {// normal " (without \ before) insideQuote = !insideQuote; // starts or ends quotation } // commas that are outside quote or last character in line // should invoke adding non-empty builder to list if (ch == ',' &amp;&amp; !insideQuote || i == line.length() - 1) { if (tokenBuilder.length() &gt; 0) { tokens.add(tokenBuilder.toString().trim()); tokenBuilder.delete(0, tokenBuilder.capacity()); } } // add every character to builder except \ that are inside // quotes and have " after it else if (!(ch == '\\' &amp;&amp; i + 1 &lt; line.length() &amp;&amp; line.charAt(i + 1) == '"' &amp;&amp; insideQuote)) { tokenBuilder.append(ch); } prev = ch;//in next loop previous character should be our current one } String[] array = tokens.toArray(new String[tokens.size()]); for (String s : array) System.out.println("&gt;" + s); </code></pre> <p>Output:</p> <pre><code>&gt;"start "title" end" &gt;10 &gt;20 &gt;"text </code></pre>
    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.
 

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