Amazon.com Widgets HasPrefix Suffolk Method Attempt
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 25, 2013, 05:12:08 AM
Home Help Search chat Login Register   
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+  Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+  Old Stuff
| |-+  Webcast Series Part II, Oct. 1 - 27
| | |-+  Example using hasPrefix: and hasSufix:
| | | |-+  HasPrefix Suffolk Method Attempt
Pages: [1]   Go Down
Print
Author Topic: HasPrefix Suffolk Method Attempt  (Read 730 times)
mfriedzz
Newbie
*
Posts: 8






« on: October 07, 2009, 05:58:30 PM »

Hello,

Here is my attempt.  Very simple.
//
//  main.m
//  hasPreSuffix
//
//  Created by michael friedman on 10/7/09.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//
#import <Foundation/Foundation.h>
 
int main (int argc, const char * argv[]) {
   NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
   
   NSLog (@"Here is the Prefix Suffolk Method");
   
   NSString *str1 = @"Here is String A";
   NSString *str2 = @"Here";
   NSString *str3 = @"There";
   NSString *str4 = @"String A";
   NSString *str5 = @"String C";
   
   Boolean answer;
   
   answer = [str1 hasPrefix:str2];
   NSLog (@"'Here' is a Prefix Yes(1) or No(0):    %i", answer);
   answer = [str1 hasPrefix:str3];
   NSLog (@"'There' is a Prefix Yes(1) or No(0):    %i", answer);
   answer = [str1 hasSuffix:str4];
   NSLog (@"'String A' is a Suffix Yes(1) or No(0):    %i", answer);
   answer = [str1 hasSuffix:str5];
   NSLog (@"'String C' is a Suffix Yes(1) or No(0):    %i", answer);
   
   
    [pool drain];
    return 0;
}



[Session started at 2009-10-07 20:49:22 -0400.]
2009-10-07 20:49:22.086 hasPreSuffix[2101:10b] Here is the Prefix Suffolk Method
2009-10-07 20:49:22.103 hasPreSuffix[2101:10b] 'Here' is a Prefix Yes(1) or No(0):    1
2009-10-07 20:49:22.104 hasPreSuffix[2101:10b] 'There' is a Prefix Yes(1) or No(0):    0
2009-10-07 20:49:22.104 hasPreSuffix[2101:10b] 'String A' is a Suffix Yes(1) or No(0):    1
2009-10-07 20:49:22.105 hasPreSuffix[2101:10b] 'String C' is a Suffix Yes(1) or No(0):    0

The Debugger has exited with status 0.
Logged
skochan
Administrator
Hero Member
*****
Posts: 3106







« Reply #1 on: October 07, 2009, 07:02:30 PM »

Simple is good!

Just to keep things straight, the two NSString methods are defined to return a value of type BOOL, not Boolean (Maybe you found the documentation for Core Foundation's CFStringHasPrefix and CFStringHasSuffix functions that return a Boolean value?).  In the long run, it makes no difference, but it's best to try to keep these oftentimes confusing boolean types/values consistent (see my reply to a post in Chapter 6 about BOOL, TRUE, YES, etc.).


Cheers,

Steve Kochan
« Last Edit: October 07, 2009, 07:04:04 PM by skochan » Logged
Pages: [1]   Go Up
Print
Jump to:  



Login with username, password and session length

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 (c) 2009 classroomM.com. All rights reserved.