Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
October 20, 2018, 02:33:25 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register Chat  
Pages: [1]   Go Down
  Print  
Author Topic: Prefix and Suffix Code  (Read 4405 times)
highvelocity
Newbie
*
Posts: 1


Email
« on: January 12, 2010, 04:14:47 PM »

Here's what I came up with:

Code: (Objective-C)
#import <Foundation/Foundation.h>

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

NSString *testString = [[NSString alloc] initWithString: @"This is a test string!"];

NSLog(@"testString = %@",testString);

    if ([testString hasPrefix: @"This"]) {
NSLog(@"The prefix 'This' exists.");
}
else {
NSLog(@"The prefix 'This' doesn't exist.");
}


if ([testString hasPrefix: @"That"]) {
NSLog(@"The prefix 'That' exists.");
}
else {
NSLog(@"The prefix 'That' doesn't exist.");
}

    if ([testString hasSuffix: @"!"]) {
NSLog(@"The suffix '!' exists.");
}
else {
NSLog(@"The suffix '!' doesn't exist.");
}

    if ([testString hasSuffix: @"!"]) {
NSLog(@"The suffix 'string!' exists.");
}
else {
NSLog(@"The suffix 'string!' doesn't exist.");
}

[testString release];
    
[pool drain];
    return 0;
}

Results:
2010-01-12 16:14:25.405 PrefixAndSuffix[15024:a0f] testString = This is a test string!
2010-01-12 16:14:25.412 PrefixAndSuffix[15024:a0f] The prefix 'This' exists.
2010-01-12 16:14:25.413 PrefixAndSuffix[15024:a0f] The prefix 'That' doesn't exist.
2010-01-12 16:14:25.413 PrefixAndSuffix[15024:a0f] The suffix '!' exists.
2010-01-12 16:14:25.414 PrefixAndSuffix[15024:a0f] The suffix 'string!' exists.
« Last Edit: January 14, 2010, 01:09:07 PM by happyzhb » Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents ゥ 2009 classroomM.com. All rights reserved.