Objective-C (cocoa) equivalent to python’s endswith/beginswith

Use -hasPrefix: and -hasSuffix::

NSString *s = @"foobar";
NSLog(@"%d %d\n", [s hasPrefix:@"foo"], [s hasSuffix:@"bar"]);
// Output: "1 1"

Leave a Comment