Reputation: 17591
I must verify the beginning of a string: my example string is
NSString *string1 = @"Hello World";
then I must do an if, example:
if (string1 startwith "Hello")
How can I do this in objective c?
Upvotes: 5
Views: 7863
Reputation: 16861
Read the documentation for the NSString class. You'll find all kinds of surprises.
Upvotes: 2
Reputation: 3847
How about doing it this way:
NSRange aRange = [myString rangeOfString:@"Hello"];
if (aRange.location ==NSNotFound) {
NSLog(@"string not found");
} else {
NSLog(@"string was at index %d ",aRange.location);
}
Based on the range, you can determine where in the string the item occurs
Upvotes: 1