Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Classes.. :(

Classes.. :(
Thread Tools
Fresh-Faced Recruit
Join Date: Jun 2003
Status: Offline
Reply With Quote
Jun 21, 2003, 05:24 AM
 
hi,

i have 3 files in a foundation tool, main.m, scanner1.h, scanner1.m:

main.m:

#import <Foundation/Foundation.h>
#import "scanner1.h"

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


NSString *returnstring;
returnstring = [[NSString alloc] _scanString:@"\\valuen\\xak2dj\\blahblah\\xyz\\val ue1\\1\\value2\\teststring" startTag:@"\\value2" endTag:@""];
NSLog(@"Result = %@", returnstring);
[pool release];
return 0;
}

scanner1.h:

#import <Foundation/Foundation.h>


@interface scanner1 : NSObject {
NSString *_scanString;
}

-(NSString *)_scanString:(NSString *)source startTag:(NSString *)startTag endTag:(NSString *)endTag;

@end

scanner1.m:

#import "scanner1.h"


@implementation scanner1

-(NSString *)_scanString:(NSString *)source startTag:(NSString *)startTag endTag:(NSString *)endTag
{
NSScanner *scanner = [NSScanner scannerWithString:source];
NSString *result;

//find start tag
if (![scanner scanUpToString:startTag intoString:nil])

//not found!
return nil;

//skip over the strat tag we found
[scanner scanString:startTag intoString:nil];

//then scan up to the end tag in the result
[scanner scanString:endTag intoString:&result];

//see if the end tag actually exists, if so return the result, if not return nil
if ([scanner scanString:endTag intoString:nil])
return result;
else
return nil;
}


@end


i just want to scan out what after value2\\ comes. (and what after \\valueX comes)but this doesn't work! anyone knows where the problem is?
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Jun 21, 2003, 07:23 AM
 
You do realize that the string "\\" actually represents a single backslash, right? Because \ is the escape character.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
Dapp  (op)
Fresh-Faced Recruit
Join Date: Jun 2003
Status: Offline
Reply With Quote
Jun 21, 2003, 08:49 AM
 
yes, \\ is \. that's what i want. i have found the problem now:

-(NSString *)_scanString:(NSString *)source startTag:(NSString *)startTag endTag:(NSString *)endTag
{
NSScanner *scanner = [NSScanner scannerWithString:source];
NSString *result;
NSString *errormsg =@"startTag not found";
NSString *errormsg1 =@"endTag not found";

[scanner scanUpToString:startTag intoString:nil];

if ([scanner scanString:startTag intoString:nil])
{
if ([scanner scanUpToString:endTag intoString:&result])
return result;
}
}

------------------
NSString *re;
scanner1 *scanner = [[scanner1 alloc] init];
re = [scanner _scanString:@"This is a Test" startTag:@"This" endTag:@"a"];
NSLog(@"Result is %@",re);

.---> Result is is ;)
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 03:44 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2