title: Parsing a string and printing string literals to screen
body: <p>I am trying to print any string literals I have in a file I am reading using a scan method. I am limited to follow a guide as to the structure of my programme, by my professor.</p>
  <p>Currently, I have this section of code that is printing string literals, or is trying to:</p>
  <pre><code>public static void scan (String prog) {
      
              int n = prog.length();
              int index = 0;
              int lineNumber = 1;
              
              
              
              while (index &lt; n) {
                  
                  char ch = prog.charAt(index);
                  
                  
                  
                  boolean whiteSpace = isWhiteSpace(ch);
                  boolean newLine = isLineBreak(ch);
                  TokenType sym = getSymbol(ch);
                  TokenType op = getOp(ch);
                  boolean letter = isLetter(ch);
                  boolean digit = isDigit(ch);
                  
                  // start of if statement preceding this point               
              
                  else if (ch == '\&quot;') {
                      String str = &quot;&quot;;
                      str += ch;
                      
                      index++;
                      
                          while (index &lt; n) {
                              
                              ch = prog.charAt(index);
                              
                                  if (ch != '\&quot;') {
                              
                                      str += ch;
                                      index++;
                                      }
                                  else break; 
                              }
                          
                          System.out.println(lineNumber + &quot;,&quot; + TokenType.STRING + &quot;, &quot; + str);
                          index++;
                          continue;           
                  }
                  else {
                      System.out.println(&quot;Encountered something not expected: &quot; + ch);
                      index++;
                      continue;
                  } 
                  
          
  </code></pre>
  <p>This outputs the first <code>&quot;</code> and all the characters before the next <code>&quot;</code> but not the last <code>&quot;</code> of the string literal itself. How can I go about changing this code to print the whole string literal?</p>
  <p>Current output:</p>
  <pre><code>11, STRING, &quot;This just random code
  </code></pre>
  <p>What I need:</p>
  <pre><code>11, STRING, &quot;This just random code&quot;
  </code></pre>