Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.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
Ios stringByReplacingOccurrencesOfString:donds';行不通_Ios_Nsstring - Fatal编程技术网

Ios stringByReplacingOccurrencesOfString:donds';行不通

Ios stringByReplacingOccurrencesOfString:donds';行不通,ios,nsstring,Ios,Nsstring,我希望我的输出是“23”,但它仍然显示“123” stringByReplacingOccurrencesOfString返回一个新字符串: 或者,您可以使用NSMutableString并使用 replaceCurrencesofString:with字符串:选项:范围:方法。您不会再次将返回的字符串分配给valorTextField。您只是在执行函数。实际字符串不变。改为写: valorTextField = [valorTextField stringByReplacingOccurre

我希望我的输出是“23”,但它仍然显示“123”


stringByReplacingOccurrencesOfString
返回一个新字符串:

或者,您可以使用
NSMutableString
并使用
replaceCurrencesofString:with字符串:选项:范围:
方法。

您不会再次将返回的字符串分配给
valorTextField
。您只是在执行函数。实际字符串不变。改为写:

valorTextField  = [valorTextField stringByReplacingOccurrencesOfString:@"1" withString:@""];
NSLog(@"%@", valorTextField);

可以这样尝试:
NSString*valorTextField;valorTextField=@“123”;[valorTextField StringByReplacingOfString:@“1”和字符串:@”“;NSLog(@“%@”,valorTextField)
当然,您可以为
valorTextField
指定一个新值。不可变意味着您无法修改
valorTextField
指向的字符串对象。抱歉,我误解了这一点。。谢谢你指出:)
NSString *valorTextField = [[NSString alloc] initWithFormat:@"123"];
NSString *replaced = [valorTextField stringByReplacingOccurrencesOfString:@"1" withString:@""];
NSLog(@"%@", replaced);
valorTextField  = [valorTextField stringByReplacingOccurrencesOfString:@"1" withString:@""];
NSLog(@"%@", valorTextField);