I'm working on a project, and I need to skip all lines that begin with '"'. I have this code:
String line = reader.readLine();
boolean containsChar;
try { containsChar = line.charAt(0) != '\"'; }
catch (Exception ex) { containsChar = true; }
while (line != null && containsChar) {
line = reader.readLine();
try { containsChar = line.charAt(0) != '\"'; }
catch (Exception ex) { containsChar = true; }
}
I used to have a short piece of code, but that would detect any line which contains a '"' anywhere in the line:
while (line != null && !line.contains("\"")) { line = reader.readLine(); }
I had a short way of doing it, but it is possible for a line to be empty. In this case the code returns an exception:
while (line != null && line.charAt(0) != '\"') { line = reader.readLine(); }
Question: Is it possible to have code similar to the code below, where the try-catch is inside of the while test?
while (line != null && (try { line.charAt(0) != '\"'; }catch (Exception ex) { true; })) { line = reader.readLine(); }
Solution: In one of the comments Thilo gave a solution which works with a char at any index (in this example index 12):
( line.length() > 12 && line.charAt(12) == something)