Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OBjective C: check the beginning of a string

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?

like image 407
cyclingIsBetter Avatar asked Apr 14 '11 10:04

cyclingIsBetter


2 Answers

if ([string1 hasPrefix:@"Hello"])
like image 101
Jim Blackler Avatar answered Oct 01 '22 02:10

Jim Blackler


Read the documentation for the NSString class. You'll find all kinds of surprises.

like image 33
NSResponder Avatar answered Oct 01 '22 01:10

NSResponder