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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to