开发者

Finding a not constant char.set in an NSString

开发者 https://www.devze.com 2023-02-15 06:56 出处:网络
I have an NSString with data for ex.: {SCENE*169/doprava/doprava_tabulka {} {} {} 1299234095} {SCENE*169/doprava/doprava_video {} {} {} 1299234166}

I have an NSString with data for ex.:

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

I would like delete parts "brackests and the number", but the numers are not constatnt.

{} 开发者_运维知识库{} {} 1299234095 {} {} {} 1299234166

How can I delete this?


I'd use 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 value here is {SCENE*169/doprava/doprava_tabulka} {SCENE*169/doprava/doprava_video}

But if you develop for iOS, it's only available since 3.2.

0

精彩评论

暂无评论...
验证码 换一张
取 消