Note that there are some explanatory texts on larger screens.

plurals
  1. POescape character using indexOf()
    primarykey
    data
    text
    <p>I'm reading a file line by line into sting and split it into smaller strings using <code>line.indexOf('"', 1)</code> and <code>substring()</code> but this way doesn't detect whether before <code>"</code> is <code>\</code> or not so it doesn't react to escape char. how do I solve this?</p> <p>(I cannot just use <code>line.split('"')</code> couse <code>"</code> are both at beginning and ending of substring, nor split by other char, cause my task does not allow so.)</p> <p>the whole reading segment is: </p> <pre><code>while ((line = bufferedReader.readLine()) != null) { System.out.println(line); while(line.length()&gt;0){ if(line.charAt(0) == ',' || line.charAt(0) == ' '){ line = line.substring(1); } else{ if(line.indexOf(',') != -1){ if (line.charAt(0) == '"'){ pabaiga = line.indexOf("\"", 1); zodis = line.substring(0, pabaiga+1); line = line.substring(pabaiga+1); duomenys.add(zodis); } else{ pabaiga = line.indexOf(','); zodis = line.substring(0, pabaiga); line = line.substring(pabaiga); duomenys.add(zodis); } } else{ zodis = line; line = line.substring(line.length()); duomenys.add(zodis); } } for(String elem : duomenys){ System.out.println(elem); } duomenys.removeAll(duomenys); } </code></pre> <p>I was not allowed to split only by , separator as there could be one in the middle of the string, using \, in text file was not an option. So I was suggested to determine one sting element as " text" but if it contains another " or \" in the middle, my current code doesnt work.</p> <p>if my line from text file is <code>"start \"title\" end", 10, 20, "text"</code><br> the sting array should contain </p> <ul> <li>[0] <code>"start "title" end"</code> </li> <li>[1] <code>10</code> </li> <li>[2] <code>20</code> </li> <li>[3] <code>"text"</code></li> </ul>
    singulars
    1. This table or related slice is empty.
    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