title: Parsing G-code with arduino from an sd card
body: <p>As the title suggests, I am using the following function to read the parameters of some g-code files present on the SD card:</p>
  
  <pre><code>long parseParameters(String data, char* c){
      int offset = data.indexOf(c);
      int offset1 = data.lastIndexOf(" ", offset + 1);
      return offset1 &gt; 0 ? data.substring(offset + 1, offset + offset1 + 1).toInt() : data.substring(offset + 1).toInt();
  }
  
  void setup(){
      Serial.begin(9600);
      String q = "P3 S255"; // input
      Serial.println(parseParameters(p, "S")); // output
  }
  
  void loop(){
  
  }
  </code></pre>
  
  <p>Only today, in an attempt to read the value of <strong>S</strong> in the string <strong>P3 S255</strong> has emerged in a small bug:</p>
  
  <pre><code>INPUT -&gt; OUTPUT
  P3 S255 -&gt; 25 (wrong)
  A20 P3 S255 -&gt; 255 (Correct)
  S255 -&gt; 255 (Correct)
  </code></pre>
  
  <p>Why? Yet the code would seem correct to me..where did I go wrong?</p>
  
  <p>Thanks in advance to everyone.. :)</p>