I'm trying to remove a string from an NSString.
I have the Device Name
NSString * deviceName = [NSString stringWithFormat:@"%@", [[UIDevice currentDevice] name]];
and I'm trying to remove the 's iPhone 's iPod & 's iPad. How do I go about this? I've tried stringByReplacingOccuranceOfString
but that didn't work. Any Ideas?
This works for me:
NSString *deviceName = @"Kenny's iPhone";
NSString *stripped = [deviceName stringByReplacingOccurrencesOfString:@"'s iPhone" withString:@""];
The stripped variable has the string @"Kenny" after that line. Remember that -stringByReplacingOccurrencesOfString: doesn't alter your existing string, it returns a new string with the changes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With