title: How to use tokenizer in java with , delimiters?
body: <p>I have a sample input file as follows - </p>
  
  <blockquote>
    <p>OPCODE R1, R2, R3<br>
    OPCODE R2, #30</p>
  </blockquote>
  
  <pre><code>while(scanner.hasNextLine()){
      StringTokenizer st = new StringTokenizer(scanner.nextLine());
      Instruction instruction = new Instruction();
      instruction.setAddress(PC + PC_increment);
      instruction.setOpcode(st.nextToken());
      if(st.hasMoreTokens()) {
          instruction.setDest(st.nextToken());
      }
      if(st.hasMoreTokens()) {
          String nextToken = st.nextToken();
          if(nextToken.charAt(0)== '#') {
              instruction.setSource_1(nextToken.split("#")[1]);
          } 
          else {
              instruction.setSource_1(nextToken);
          }
      }   
      if(st.hasMoreTokens()) {
          instruction.setSource_2(st.nextToken());
      }
  }
  </code></pre>
  
  <p>When I am trying to print the token I am getting "R1," and "R2," as the output. However, I am expecting just R1 or R2 as output. Also, I don't want the <code>#</code> in the case of second line. How can I do it? What am I doing wrong?</p>