tags:

views:

90

answers:

5

I´m making a dictionary (this is my test app) here is my code which not work:

- (IBAction) btnClickMe_Clicked:(id)sender {


    NSString *kw = s.text;

    NSString *encodedkw =  [kw stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

    NSString *mms = [NSString stringWithFormat: @"%@", encodedkw];

    if (mms=NULL){
     iMessageLabel.text=@"put text";
    } else if (mms=@"a"){
        iMessageLabel.text=@"this is a";
    } else if (mms=@"b"){
    iMessageLabel.text=@"this is b";
    }


}

anybody have some idea with this ? thanks ALex

+1  A: 

May it happen, that you need to call some kind of string manipulation routine like compare to compare strings, not just comparing the pointers?

Besides mms=NIL means assignment NIL to mms not comparison desired.

Upd.: NIL does not mean empty string. You should write [mms length] == 0 instead to see if the string is empty.

Li0liQ
+4  A: 

You cannot use == on NSString objects. Try doing this:

if (encodedkw == nil){
    iMessageLabel.text=@"put text";
} else if ([encodedkw isEqualToString:@"a"]){
   iMessageLabel.text=@"this is a";
} else if ([encodedkw isEqualToString:@"b"]){
   iMessageLabel.text=@"this is b";
}

mms should be equal to encodedkw so I switched to using that. Also I'm using isEqualToString for string comparison. Finally, I've changed the null check to check against nil instead of NULL.

Colin Gislason
For correctness sake, shouldn't it be:if (mms==NIL)...because Apple's APIs return "NIL" instead of "NULL"? (That being said, isn't [stringWithFormat ...] a static function that always returns something?)
Dan
Agreed on nil and the fact that it should never be nil. Updating my answer.
Colin Gislason
+1  A: 

You've used = rather than ==

Larry Watanabe
A: 

yeah thank Colin Gislason your code is help me now it work BUT:::::: how about if (mms==NULL){ it stil not work...i have test i by not put anything and click on it..the message "put text"are not showing :((((((

reagards Alex

Use comments (or editting the question), not answers, to respond. You have edit privileges on your own material, and comment privileges on your own threads.
dmckee
Oh my buddha after i put if ([mms length] == 0){ now eveything is working perfect.. I really dont know how to thank you you..you ...you and you here who have given me the help.. so happy now.....:)))))but one question please... if i will make a dictionary project which way is best ? 1. use database from my web-site 2. use sqllite inside my app 3. use this way that i´m doing now by using if else statmentthank so much eveybody
A: 

Oh my buddha after i put if ([mms length] == 0){ now eveything is working perfect.. I really dont know how to thank you you..you ...you and you here who have given me the help.. so happy now.....:)))))

but one question please... if i will make a dictionary project which way is best ? 1. use database from my web-site 2. use sqllite inside my app 3. use this way that i´m doing now by using if else statment

thank so much eveybody