Re: stringByTrimmingCharactersInSet trimming too much
Re: stringByTrimmingCharactersInSet trimming too much
- Subject: Re: stringByTrimmingCharactersInSet trimming too much
- From: Jonathan Jackel <email@hidden>
- Date: Thu, 05 Dec 2002 12:25:33 -0500
If you are interested in the numerical value, why not scan that? This
should work in place of what you had in brackets
{
int intensity;
[wordScanner scanUpToCharactersFromSet:
[NSCharacterSet decimalDigitCharacterSet]
intoString:nil];
[wordScanner scanInt:&intensity];
}
If you really need a string instead of an int, you can use stringWithFormat:
to make one. If you need another type (e.g., float), check the methods
under "Scanning a string" in the NSScanner docs.
If you find yourself moving the scan position or trimming the strings you
get out of a scanner, that's a good indication there may be an easier way.
Jonathan
on 12/5/02 10:57 AM, Graeme Nattress at email@hidden wrote:
>
Hi,
>
>
I'm parsing this line of a text file:
>
>
LightSource "ambientlight" 1 "intensity" [1]"lightcolor" [0 0 0]
>
>
and when I get to extract the intensity, everything is fine until I try
>
to trim off the leading space and square bracket. Before trimming, word
>
= " [1", and after trimming it's equal to "", which doesn't seem
>
right.... Any ideas. The code snippet below is what I'm using, and it's
>
working just great for extracting other values.
>
>
[wordScanner scanUpToString:@"intensity" intoString:nil];
>
if ([wordScanner scanString:@"intensity" intoString:nil]) {
>
[wordScanner setScanLocation:[wordScanner scanLocation] + 1];
>
[wordScanner scanUpToCharactersFromSet:[NSCharacterSet
>
characterSetWithCharactersInString:@"\"]" ] intoString:&word];
>
word = [word stringByTrimmingCharactersInSet:[NSCharacterSet
>
characterSetWithCharactersInString:@" \"[]" ]];
>
intensityString = word;
>
}
>
>
Thanks,
>
>
Graeme
>
_______________________________________________
>
cocoa-dev mailing list | email@hidden
>
Help/Unsubscribe/Archives:
>
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
>
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.