stringByReplacingOccurrencesOfString:不起作用(stringByReplacingOccurrencesOfString: doesn't work)
我希望我的输出为“23”,但它仍显示“123”。
NSString *valorTextField = [[NSString alloc] initWithFormat:@"123"]; [valorTextField stringByReplacingOccurrencesOfString:@"1" withString:@""]; NSLog(@"%@", valorTextField);I want my output to be "23", but it still shows "123".
NSString *valorTextField = [[NSString alloc] initWithFormat:@"123"]; [valorTextField stringByReplacingOccurrencesOfString:@"1" withString:@""]; NSLog(@"%@", valorTextField);最满意答案
stringByReplacingOccurrencesOfString返回一个新字符串:
NSString *valorTextField = [[NSString alloc] initWithFormat:@"123"]; NSString *replaced = [valorTextField stringByReplacingOccurrencesOfString:@"1" withString:@""]; NSLog(@"%@", replaced);或者,您可以使用NSMutableString并使用replaceOccurrencesOfString:withString:options:range:方法。
stringByReplacingOccurrencesOfString returns a new string:
NSString *valorTextField = [[NSString alloc] initWithFormat:@"123"]; NSString *replaced = [valorTextField stringByReplacingOccurrencesOfString:@"1" withString:@""]; NSLog(@"%@", replaced);Alternatively, you can work with a NSMutableString and use the replaceOccurrencesOfString:withString:options:range: method.
更多推荐
发布评论