开发者

comparing strings,iphone

开发者 https://www.devze.com 2023-01-19 21:09 出处:网络
i have 2 strings say 开发者_运维知识库string A and String B i need to check if they both are eqaul or not,

i have 2 strings say 开发者_运维知识库string A and String B i need to check if they both are eqaul or not, so did this

if(a==b){
//they are equal
}

on console they both are showing same value say 'hey'. but condition is not working for me. is there any other condition to check if 2 strings are equal.

like there is on

if([A isEqualToString : @"equal"])
{
}

but this i cant fit string B in this condition, can i?/

suggestions are always appreciated


[A isEqualToString : B];

should work just fine.

When you do

if(a==b)...

you are not comparing the strings but the pointers. This means, it'll only return true if A is exactly the same string as B (with the same memory address). If they they are equal, but not the same (so, e.g. if you store @"string" in two different places in your memory), you'll get a 'false'.

0

精彩评论

暂无评论...
验证码 换一张
取 消