gpt4 book ai didi

ios - NSMutableString 追加不起作用

转载 作者:行者123 更新时间:2023-11-28 20:08:31 26 4
gpt4 key购买 nike

我有以下将字符串数组转换为字符串的代码

-(NSString *) arrayToString:(NSMutableArray *) array {
NSMutableString *strFinal = [[NSMutableString alloc] init ];

for(int i =0; i < [array count]; i ++){
NSLog(@"ARRAY STRING %@", [array objectAtIndex:i]);
[strFinal appendString:[array objectAtIndex:i]];
}
return strFinal;
}

当我运行代码时,它正确地附加了从服务器检索到的大约 20 个字符串(它们是 base64 编码图像字符串的子字符串),但是当我尝试附加它们时,它只给出了第一个和最后一个附加在一起的字符串?

Nslog 为每个数组元素返回正确的 nsstring

最佳答案

您可以通过使用 NSArraycomponentsJoinedByString: 方法完全绕过对您的方法的需要:

NSString *result = [array componentsJoinedByString:@""];

关于ios - NSMutableString 追加不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21174822/

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