代码片段如下:
unichar chars[] = {0x0030, 0x0031, 0x0032, 0x003B, 0x0E31};//the testString is "012;" plus a thai character
NSString *testString = [[NSString alloc] initWithCharacters:chars length:5];
NSLog(@"testString %@", testString);
NSScanner *theScanner = [NSScanner scannerWithString:testString];
NSString *result = nil;
[theScanner scanUpToString:@";" intoString:&result];
//[theScanner scanUpToCharactersFromSet:[NSCharacterSet characterSetWithCharactersInString:@";"] intoString:&result];
NSLog(@"the result is %@", result);
使用 scanUpToString 失败,但是,使用 scanUpToCharactersFromSet 有效。如果 0x003B 之后的字符不是 0x0E31,例如 ,0x0030,则两个 api 都可以。所以我猜 scanUpToString 有一个处理某些字符的错误。有没有人有更好的想法?谢谢你。