I need to change a string value if it meets certain criteria, but I’m not having any luck so far. I’m not sure if it’s the input string or if I’m doing something fundamentally wrong – here’s my code:
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSMutableString *stadium = [NSMutableString stringWithString:[prefs stringForKey:@"stadiumname"]];
NSLog(@"stadium: %@", stadium);
if([prefs stringForKey:@"stadiumname"]==@"Brighton & Hove")
{
[stadium setString:@"Hove"];
}
if([prefs stringForKey:@"stadiumname"]==@"Monmore Green")
{
[stadium setString:@"Monmore"];
}
NSLog(@"stadium: %@", stadium);
In the NSLog output on both sides I still get “Brighton & Hove” or “Monmore Green”, rather than just “Hove” or “Monmore” as I was expecting. I’ve tried changing the input field to allow for possible encoding by doing:
NSMutableString *stadium = [NSMutableString stringWithString:[[prefs stringForKey:@"stadiumname"] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
but that makes no difference. Would NSLog show up any encoding in the string anyway?
I just need to be able to use the shortened string once it comes out the other side, but so far no luck.
Can anyone enlighten me?
it’s because of how you compare the string, so instead of
use