Saturday, May 18, 2013

NSString integerValue example ios

[NSString integerValue]

Returns the NSInteger value of the receiver’s text.
- (NSInteger)integerValue
Return Value
The NSInteger value of the receiver’s text, assuming a decimal representation and skipping whitespace at the beginning of the string. Returns 0 if the receiver doesn’t begin with a valid decimal text representation of a number.
Discussion of [NSString integerValue]
This method uses formatting information stored in the non-localized value; use anNSScanner object for localized scanning of numeric values from a string.
Example of [NSString integerValue]
NSInteger theValue = [[data substringWithRange:NSMakeRange(0,3)] integerValue];
NSNumber* boxedValue = [NSNumber numberWithInteger:theValue];
[statsHolder addObject:theValue];
Example of [NSString integerValue]
NSString *x = @"12345";
NSInteger nsint = [x integerValue];  
NSLog(@"%d", nsint);
Example of [NSString integerValue]
#import "RegexKitLite.h"
NSString * original = @"foo 220hello";
NSString * number = [original stringByMatching:@"[^\\d]*(\\d+)" capture:1];
return [number integerValue];