如何将数组中的文本与其他字符串一起打印?
如何将数组中的文本与其他字符串一起打印?
这个问题已经有了答案:
我刚接触Objective-C,但我找不到直接解决我的问题的方法,即如何在数组值后面或前面添加字符串。
我尝试从数组中获取一些文本,并在其后面或前面添加其他字符串(将用于tableviewcell)。在Android中,只需使用+号即可工作,这就是我无法在这里处理它的原因。
我尝试像下面这样做:
"some text" +[arrayName objectAtIndex:indexPath.row] + "some text"
admin 更改状态以发布 2023年5月21日
简短的:
[NSString stringWithFormat:@"%@/%@/%@", "some text", [arrayName objectAtIndex:indexPath.row], "some text"];
你需要使用stringWithFormat
来连接这些值,或者你也可以使用NSMutableString
使用以下方式
NSString* finalText = [NSString stringWithFormat:@"some text %@ some text",[arrayName objectAtIndex:indexPath.row]];
另一种方式
NSMutableString* finalString = [NSMutableString stringWithString:@"test Text"]; [finalString appendString:[arrayName objectAtIndex:indexPath.row]]; [finalString appendString:@"test Text 2"];