我是Objective-C的新手,我无法找到解决问题的直接解决方案,其中解释了如何在数组值后面或前面添加字符串。 我尝试从数组中获取一些文本,并在其后面或前面添加一些其他字符串(将在tableviewcell中使用)。在Android中它只使用+符号,这就是为什么我在这里无法处理它。 我尝试做类似下面的事情:
"some text" +[arrayName objectAtIndex:indexPath.row] + "some text"
答案 0 :(得分:1)
您需要使用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"];
答案 1 :(得分:0)
短:
[NSString stringWithFormat:@"%@/%@/%@", "some text", [arrayName objectAtIndex:indexPath.row], "some text"];
如需进一步解答,请参阅:https://stackoverflow.com/a/510444/9310455