• 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
Three more questions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Three more questions


  • Subject: Three more questions
  • From: William Squires <email@hidden>
  • Date: Sun, 14 Nov 2010 10:12:39 -0600

1) What's the best way to get an NSUInteger from an NSString that has a string representation of a valid unsigned 32 bit integer (0..4,294,967,295). There's an [NSString integerValue] and an [NSString longLongValue] (int64 anyone?), but not convenience methods on NSString that return an unsigned integer value.

Here's my try: (given an NSString *s with the numerical representation)

...
long long i = [s longLongValue];
// Get the lower 32 bits of i into l
NSUInteger l = (NSUInteger)(i % 4294967296);

'l' should - I hope - now have the NSUInteger value that 's' represents.

2) Also, how can I make an NSTextField only allow valid unsigned 32 bit integers to be typed in?
3) Finally, what's the simplest way to do a search and replace on an NSString of the form @"x####" (where "#" is replaced with valid characters in the range '0'..'9') so that I can, in a for-loop from 0 to 9, replace the "x" with a single digit? Something like:


NSString *oldNumber = ...; // Code to obtain the value of oldNumber, let's say "x103"
for (int i=0; i<10; ++i)
{
NSString *myNewNumber = [oldNumber replaceString:@"x" withNewString:[NSString stringWithFormat:@"%u",_
i]];


  // do something with myNewNumber...
  }

myNewNumber should take on the values; "0103", "1103", "2103", ... "9103".
I'd like to make this a category on NSString for my number crunching project I'm working on.


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Three more questions
      • From: Dave DeLong <email@hidden>
  • Prev by Date: Re: More stoopid questions...
  • Next by Date: Re: Three more questions
  • Previous by thread: Re: NSUInteger = unsigned int?
  • Next by thread: Re: Three more questions
  • Index(es):
    • Date
    • Thread