1つの番号が必要な場合は、これでうまくいくはずです。
static int ReadMeetingNumber(NSString * string) {
// ARC:
// locate the line
NSString * const prefix = @"Meeting Number: ";
NSMutableString * meetingNumberLine = nil;
for (NSString * line in [string componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]]) {
if ([line hasPrefix:prefix]) {
meetingNumberLine = [line mutableCopy];
}
}
if (nil == meetingNumberLine) {
return nil;
}
// trim and get int value
[meetingNumberLine deleteCharactersInRange:NSMakeRange(0, prefix.length)];
[meetingNumberLine replaceOccurrencesOfString:@" " withString:@"" options:0 range:NSMakeRange(0, meetingNumberLine.length)];
return meetingNumberLine.intValue;
}
個々の番号を見つけたい場合は、これでうまくいくはずです。
// ARC:
// Returns an NSArray of NSNumbers
static NSArray * ReadMeetingNumbers(NSString * string) {
// locate the line
NSString * const prefix = @"Meeting Number: ";
NSMutableString * meetingNumberLine = nil;
for (NSString * line in [string componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]]) {
if ([line hasPrefix:prefix]) {
meetingNumberLine = [line mutableCopy];
}
}
if (nil == meetingNumberLine) {
return nil;
}
[meetingNumberLine deleteCharactersInRange:NSMakeRange(0, prefix.length)];
// locate the numbers:
NSMutableArray * results = [NSMutableArray new];
for (NSString * at in [meetingNumberLine componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]) {
const int intValue = at.intValue;
if (0 != intValue) {
[results addObject:[NSNumber numberWithInt:intValue]];
}
}
return [results copy];
}