user23150: I meet a terrible problem. I can't compare two string!
My job is simple, every 1ms use SoftwareSerial read_card(2, 3);to check if i read a id card.And don't read a card twice.Here are my code:
bool CardReader::check()
{
    String str= read_card.readString();
    if (str.length() == 0 ) return false;
    //Log("card:%s", str);
    Serial.println("card_id");
    Serial.println(str);
    Serial.println(card);
    Serial.print("cmp:"); Serial.println(str == card);
    if (str.length() == card.length())
    {
        uchar *p1 = (uchar*)str.c_str(), *p2 = (uchar*)str.c_str();
        for (int i = 0; i < card.length(); i++)
            if (p1[i] != p2[i])
                break;
        return false;
    }
    card = str;
    return true;
}

Let's see output:
card_id
 Rq
 僐R 
cmp:1

The hex are:
00 01 52 71 02 
00 83 52 52 00 

Why the two string is equal?
Bugs are fixed.If string begin with '\0',== can't work and = can't work either.
bool CardReader::check()
{
    String str = read_card.readString();
    if (str.length() == 0) return false;
    if (str.length() == card.length())
    {
        uchar *p1 = (uchar*)str.c_str(), *p2 = (uchar*)card.c_str();
        for (int i=0; i < card.length(); i++)
        {
            Log("%d:%d", p1[i],p2[i]);
            if (p1[i] != p2[i])
                goto find_card;
        }
        return false;
    }
find_card:
    for(int i=0;i<5;i++)
        card[i]=str[i];
    return true;
}


user10794: 
Why the two string is equal?

        uchar *p1 = (uchar*)str.c_str(), *p2 = (uchar*)str.c_str();

Both p1 and p2 point to the same string so of course they will always compare equal.

Do you mean:
if (str == card)
   // do something


23150: <p>I meet a terrible problem. I can't compare two string!</p>

<p>My job is simple, every 1ms use <code>SoftwareSerial read_card(2, 3);</code>to check if i read a id card.And don't read a card twice.Here are my code:</p>

<pre><code>bool CardReader::check()
{
    String str= read_card.readString();
    if (str.length() == 0 ) return false;
    //Log("card:%s", str);
    Serial.println("card_id");
    Serial.println(str);
    Serial.println(card);
    Serial.print("cmp:"); Serial.println(str == card);
    if (str.length() == card.length())
    {
        uchar *p1 = (uchar*)str.c_str(), *p2 = (uchar*)str.c_str();
        for (int i = 0; i &lt; card.length(); i++)
            if (p1[i] != p2[i])
                break;
        return false;
    }
    card = str;
    return true;
}
</code></pre>

<p>Let's see output:</p>

<pre><code>card_id
 Rq
 僐R 
cmp:1
</code></pre>

<p>The hex are:</p>

<pre><code>00 01 52 71 02 
00 83 52 52 00 
</code></pre>

<p>Why the two string is equal?</p>

<p>Bugs are fixed.If string begin with '\0',<code>==</code> can't work and <code>=</code> can't work either.</p>

<pre><code>bool CardReader::check()
{
    String str = read_card.readString();
    if (str.length() == 0) return false;
    if (str.length() == card.length())
    {
        uchar *p1 = (uchar*)str.c_str(), *p2 = (uchar*)card.c_str();
        for (int i=0; i &lt; card.length(); i++)
        {
            Log("%d:%d", p1[i],p2[i]);
            if (p1[i] != p2[i])
                goto find_card;
        }
        return false;
    }
find_card:
    for(int i=0;i&lt;5;i++)
        card[i]=str[i];
    return true;
}
</code></pre>
 10794: <blockquote>
  <p>Why the two string is equal?</p>
</blockquote>

<pre><code>        uchar *p1 = (uchar*)str.c_str(), *p2 = (uchar*)str.c_str();
</code></pre>

<p>Both p1 and p2 point to the same string so of course they will always compare equal.</p>

<hr>

<p>Do you mean:</p>

<pre><code>if (str == card)
   // do something
</code></pre>
