gpt4 book ai didi

objective-c - stringByReplacingOccurrencesOfString 循环?

转载 作者:行者123 更新时间:2023-12-02 04:36:12 24 4
gpt4 key购买 nike

NSString *qwer2 = [qwer1 stringByReplacingOccurrencesOfString:@"count '0','" withString:@""];

NSString *qwer4 = [qwer2 stringByReplacingOccurrencesOfString:@"count '1','" withString:@""];

NSString *qwer = [qwer4 stringByReplacingOccurrencesOfString:@"count '2','" withString:@""];

如何用任何数字替换字符串?

count '0' , count '1' , count '2'

count 'any numbers'

我已经尝试过循环:

for (int i =0; i<100; i++) 

NSString *qwer = [qwer4 stringByReplacingOccurrencesOfString:@"count 'i','"withString:@""];

最佳答案

NSString *replaced = [string stringByReplacingOccurrencesOfString:@"count '\\d+','"
withString:@""
options:NSRegularExpressionSearch
range:NSMakeRange(0, string.length)];

应该可以解决问题。 "\d+"是匹配一个或多个数字的正则表达式模式。

关于objective-c - stringByReplacingOccurrencesOfString 循环?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21933632/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com