3

for example...

NSString string1 = @"Hello world";
NSMutableString string2 = [NSMutableString stringWithString: string1];

then... then can we compare these using following statement..? or there is any other way?

if(string1 isEqualToString:string2)

help me out please...

rockey
  • 638
  • 4
  • 16
  • 34
  • So long as you correct your if statement to read: `if([string1 isEqualToString:string2])` then yes, your code is correct. – jer Nov 27 '10 at 21:30

1 Answers1

3

yes of course. an NSMutableString is an NSString, so your code is perfectly correct, except for some syntax errors (you missed the * on each NSString and the [ ] on the if statement. You should write :

NSString *string1 = @"Hello world";
NSMutableString *string2 = [NSMutableString stringWithString:string1];

if ([string1 isEqualToString:string2])
{
    // string are equal
}
Thomas Joulin
  • 6,590
  • 9
  • 53
  • 88