如何从 NSString Xcode 中获取两个单独的值

how to get two separate value from NSString Xcode

NSString *mystring = @"123 This is testing message";

上面的字符串,我需要得到两个单独的字符串,就像下面的一样。

NSString *one = @"123";
NSString *Two = @"This is testing message";

有什么快速的方法可以从 mystring 中检索两个单独的字符串?

你可以用这个

  - (NSString *)extractNumberFromText:(NSString *)text
  {
    NSCharacterSet *nonDigitCharacterSet = [[NSCharacterSet decimalDigitCharacterSet] invertedSet];
    return [[text componentsSeparatedByCharactersInSet:nonDigitCharacterSet] componentsJoinedByString:@""];
  }

用于调用

NSString * str = @"123 This is testing message";
NSString *number = [self extractNumberFromText:str];
NSString *text = [str substringFromIndex:number.length+1];