user30773: In my code I have that string:String code = rs1 + rs2 + rs3; //rs1=034, rs2=000, rs3=017 It means that code = "034000017". But if I run if (code.equals("034000017")) Serial.println("OK"); There is nothing in serial monitor. Here is full code:
String code, rs1, rs2, rs3, readString;
void setup() {
    Serial.begin(9600);
    Serial.println("Serial ready!");
}

void loop() {
    if (Serial.available()) {
        while (Serial.available()) {
          delay(10);  
          if (Serial.available() >0) {
            char c = Serial.read();
            readString += c;
            rs1 = readString.substring(0, 3); //034
            rs2 = readString.substring(3, 6); //000
            rs3 = readString.substring(6, 9); //017
            code = rs1 + rs2 + rs3;
            Serial.println(code);
            if (code.equals("034000017")) Serial.println("OK");
          } 
        }
    }
}


user10214: In your code there is a trivial error and a conceptual error.
The trivial error is in line 16, you wrote
rs2 = readString.substring(6, 9); //017

but it should have been
rs3 = readString.substring(6, 9); //017

(3 instead of 2)
The conceptual one is that you do not have to check the string every time; if you know that the string must be 9 chars long, check for it:
void loop() {
    while (Serial.available()) {
        readString += (char)Serial.read();
        if (readString.length() >= 9) {
            rs1 = readString.substring(0, 3); //034
            rs2 = readString.substring(3, 6); //000
            rs3 = readString.substring(6, 9); //017
            code = rs1 + rs2 + rs3;
            Serial.println(code);
            if (code.equals("034000017")) Serial.println("OK");
            readString = "";
        }
    }
}

Note that in this code I cleaned up a bit your code, and MOST IMPORTANT I reset the readstring to nothing after the check (otherwise only the first string is accepted)
I left a lot of things as they were (for instance in my opinion using a string in this case is pointless - better use a byte array; or splitting the string in three for joining it again later), since I think this is part of a larger program

user-1: Lots of errors in your code. Mine is basically the same that @frarugi87's answer. 
I only have to add: when reading serial, wait for the end of line ('\r' and/or '\n') to know when you have all your data, so you don't depend on length (which can be corrupted).
Edit (on Majeko's comment)
String code, rs1, rs2, rs3, readString;
void setup()
{
  Serial.begin(9600);
  Serial.println("Serial ready!");
}

void loop()
{
  static bool inData = true;

  while (Serial.available()) {
    char c = (char) Serial.read();

    if (c != '\r' && c != '\n') {
      readString += c;
      inData = true;
    }
    else {
      if (inData) {
        rs1 = readString.substring(0, 3); //034
        rs2 = readString.substring(3, 6); //000
        rs3 = readString.substring(6, 9); //017
        code = rs1 + rs2 + rs3;
        Serial.println(code);

        if (code.equals("034000017")) {
          Serial.println("OK");
        }
        readString = "";
        inData = false;
      }
    }
  }
}

This code works for any configuration of line ending ('\r', '\n' or '\r\n'). 
It doesn't test for length (or validity or timeout); it's left as an exercise to the reader :-)
I hope it shows how code grows when making it robust in all scenarios.

30773: <p>In my code I have that string:<code>String code = rs1 + rs2 + rs3; //rs1=034, rs2=000, rs3=017</code> It means that <code>code = "034000017"</code>. But if I run <code>if (code.equals("034000017")) Serial.println("OK");</code> There is nothing in serial monitor. Here is full code:</p>

<pre><code>String code, rs1, rs2, rs3, readString;
void setup() {
    Serial.begin(9600);
    Serial.println("Serial ready!");
}

void loop() {
    if (Serial.available()) {
        while (Serial.available()) {
          delay(10);  
          if (Serial.available() &gt;0) {
            char c = Serial.read();
            readString += c;
            rs1 = readString.substring(0, 3); //034
            rs2 = readString.substring(3, 6); //000
            rs3 = readString.substring(6, 9); //017
            code = rs1 + rs2 + rs3;
            Serial.println(code);
            if (code.equals("034000017")) Serial.println("OK");
          } 
        }
    }
}
</code></pre>
 10214: <p>In your code there is a trivial error and a conceptual error.</p>

<p>The trivial error is in line 16, you wrote</p>

<pre><code>rs2 = readString.substring(6, 9); //017
</code></pre>

<p>but it should have been</p>

<pre><code>rs3 = readString.substring(6, 9); //017
</code></pre>

<p>(3 instead of 2)</p>

<p>The conceptual one is that you do not have to check the string every time; if you know that the string must be 9 chars long, check for it:</p>

<pre><code>void loop() {
    while (Serial.available()) {
        readString += (char)Serial.read();
        if (readString.length() &gt;= 9) {
            rs1 = readString.substring(0, 3); //034
            rs2 = readString.substring(3, 6); //000
            rs3 = readString.substring(6, 9); //017
            code = rs1 + rs2 + rs3;
            Serial.println(code);
            if (code.equals("034000017")) Serial.println("OK");
            readString = "";
        }
    }
}
</code></pre>

<p>Note that in this code I cleaned up a bit your code, and MOST IMPORTANT I reset the readstring to nothing after the check (otherwise only the first string is accepted)</p>

<p>I left a lot of things as they were (for instance in my opinion using a string in this case is pointless - better use a byte array; or splitting the string in three for joining it again later), since I think this is part of a larger program</p>
 -1: <p>Lots of errors in your code. Mine is basically the same that @frarugi87's answer. </p>

<p>I only have to add: when reading serial, wait for the end of line ('\r' and/or '\n') to know when you have all your data, so you don't depend on length (which can be corrupted).</p>

<p><strong>Edit (on Majeko's comment)</strong></p>

<pre><code>String code, rs1, rs2, rs3, readString;
void setup()
{
  Serial.begin(9600);
  Serial.println("Serial ready!");
}

void loop()
{
  static bool inData = true;

  while (Serial.available()) {
    char c = (char) Serial.read();

    if (c != '\r' &amp;&amp; c != '\n') {
      readString += c;
      inData = true;
    }
    else {
      if (inData) {
        rs1 = readString.substring(0, 3); //034
        rs2 = readString.substring(3, 6); //000
        rs3 = readString.substring(6, 9); //017
        code = rs1 + rs2 + rs3;
        Serial.println(code);

        if (code.equals("034000017")) {
          Serial.println("OK");
        }
        readString = "";
        inData = false;
      }
    }
  }
}
</code></pre>

<p>This code works for any configuration of line ending ('\r', '\n' or '\r\n'). </p>

<p>It doesn't test for length (or validity or timeout); it's left as an exercise to the reader :-)</p>

<p>I hope it shows how code grows when making it robust in all scenarios.</p>
