Welcome to 16892 Developer Community-Open, Learning,Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I make a comparison of two strings which are obviously identical. Unfortunately my if clause doesn′t work as expected:

NSLog(@"%@ == %@ ?",strippedString1,strippedString2);

if (strippedString1 == strippedString2) {
    [_newBuild setTextColor: [NSColor greenColor] ]; 
    [_OldBuild setTextColor: [NSColor greenColor] ]; 
}

This is my NSLog output: Build: 2A12-046 == Build: 2A12

Even a byte by byte comparison says both strings are identical:enter image description here

Any clues ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.8k views
Welcome To Ask or Share your Answers For Others

1 Answer

With == you are comparing pointer address, to compare the contents of the strings you could use:

 [strippedString1 isEqualToString: strippedString2];

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to 16892 Developer Community-Open, Learning and Share
...