• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: stringByTrimmingCharactersInSet trimming too much
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >stringByTrimmingCharactersInSet trimming too much (From: Graeme Nattress <email@hidden>)

  • Prev by Date: Re: stringByTrimmingCharactersInSet trimming too much
  • Next by Date: Re: help with copy: method
  • Previous by thread: Re: stringByTrimmingCharactersInSet trimming too much
  • Next by thread: problem with Textfields
  • Index(es):
    • Date
    • Thread