Sunday, May 15, 2011

NSString hasPrefix example objc

NSString:hasPrefix checks whether the given NSString object contains a specified string as its beginning characters. Following code fragment shows an example of NSString:hasPrefix method.

NSString    *str = @"start_prefix  mystring  ending_suffix";

if( [str  hasPrefix:@"sta"] )
{
    NSLog(@"The string starts with sta");
}