If I have an NSString that is initially:
"ABCDE*FGHI"
How do I make it turn into
"FGHI"
In other words, everything from the asterisk onwards is kept.
Likewise, how would I turn it into:
"ABCDE"
(everything up to the asterisk is kept)
Thanks
NSString *myString = @"ABCDE*FGHI";
NSArray *myArray = [myString componentsSeparatedByString:@"*"];
If you want more than one character to be the separator,
use componentsSeparatedByCharactersInSet
:
NSString *myString = @"ABCDE*FGHI-JKL";
NSArray *myArray = [myString componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"*-"]];
NSString *myString = @"ABCDE*FGHI";
NSString *subString = [myString substringWithRange: NSMakeRange(0, [myString rangeOfString: @"*"].location)];
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