Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 在NSString中查找非常量char.set_Objective C_Cocoa_Cocoa Touch - Fatal编程技术网

Objective c 在NSString中查找非常量char.set

Objective c 在NSString中查找非常量char.set,objective-c,cocoa,cocoa-touch,Objective C,Cocoa,Cocoa Touch,我有一个NSString,其中包含以下数据: {SCENE*169/doprava/doprava_tabulka{}{{}{{}1299234095}{SCENE*169/doprava/doprava_video{}{}{}1299234166} 我想删除“括号和数字”部分,但数字不是常量 {}{}{}{}1299234095 {}{}{}{}1299234166 如何删除此项 我会使用NSRegularExpression NSRegularExpression *regex = [NSR

我有一个NSString,其中包含以下数据:

{SCENE*169/doprava/doprava_tabulka{}{{}{{}1299234095}{SCENE*169/doprava/doprava_video{}{}{}1299234166}

我想删除“括号和数字”部分,但数字不是常量

{}{}{}{}1299234095 {}{}{}{}1299234166


如何删除此项

我会使用
NSRegularExpression

NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:
                              @"((?: \\{\\}){3} [0-9]+)" options:0 error:nil];
NSMutableString *str = [NSMutableString stringWithString:
                        @"{SCENE*169/doprava/doprava_tabulka {} {} {} 1299234095} {SCENE*169/doprava/doprava_video {} {} {} 1299234166}"];

[regex replaceMatchesInString:str options:0 range:NSMakeRange(0, [str length]) withTemplate:@""];
str
这里的值是
{SCENE*169/doprava/doprava_tabulka}{SCENE*169/doprava/doprava_video}


但是如果您为iOS开发,它只能从3.2开始使用。

我可以从您的代码中使用类似于:@“((?:\\{\}){3}[0-9]+)”的方法:“StringByReplacingOfString:withString:”这样会更容易。但是我无法编写此条件的良好格式否,
stringByReplacingOccurrencesOfString:withString:
仅替换常量子字符串。