Iphone NSScanner文本的返回范围
我有一个字符串,我想在这里提取一个子字符串 文本如下所示:Iphone NSScanner文本的返回范围,iphone,objective-c,cocoa-touch,Iphone,Objective C,Cocoa Touch,我有一个字符串,我想在这里提取一个子字符串 文本如下所示: commentText=Hi+there%21&x=28&y=22 我想提取从第一个=到第一个&x的所有内容 因此,最终的文本将是: Hi there *我知道在我把它隔离后,我将不得不逃离文本 谢谢 试试这样的方法: NSString *result = nil; NSScanner *scanner = [NSScanner scannerWithString: commentText=Hi+there%21&a
commentText=Hi+there%21&x=28&y=22
我想提取从第一个=到第一个&x的所有内容
因此,最终的文本将是:
Hi there
*我知道在我把它隔离后,我将不得不逃离文本
谢谢 试试这样的方法:
NSString *result = nil;
NSScanner *scanner = [NSScanner scannerWithString: commentText=Hi+there%21&x=28&y=22];
[scanner scanUpToString:@"=" intoString:nil];
[scanner scanUpToString:@"&" intoString:&result];
成功了!因为“=”仍然存在,所以我必须创建一个子字符串:result=[result substringfromfromindex:1];已删除标记“xcode”