简体   繁体   English

如何在Objective c中将int数组转换为NSString?

[英]How do I convert an array of ints to a NSString in Objective c?

First off, I'm pretty new to coding so bear with me if this is a dumb question. 首先,我对编码很新,所以如果这是一个愚蠢的问题请耐心等待。 I don't know how to convert soemthing like int array[10] into a single NSString. 我不知道如何将int array [10]之类的soemthing转换为单个NSString。 I've been searching for solutions, but so far, all i've seen is converting from an array to an string array. 我一直在寻找解决方案,但到目前为止,我所看到的只是从数组转换为字符串数组。

First thing I tried was something like 我试过的第一件事就像是

NSString *String=[NSString stringWithFormat @"%i",array];

But the thing is, i know that I can do something like 但问题是,我知道我可以做类似的事情

NSString *String[NSString stringWithFormat @"%i%i%i...",array[0],array[1],array[2],.....];

But i'm trying to avoid that since I will be doing this for more than 10 variables and I will be doing it quite a bit with seperately named variables 但是我试图避免这种情况,因为我将为10个以上的变量做这个,而且我将使用单独命名的变量进行相当多的操作

int i[] = {1,2,3,4,5,6,7};

int len = sizeof(i) / sizeof(int);

NSMutableString * str = [NSMutableString string];
for (int j = 0; j<len; j++) {
    [str appendFormat:@"%i ", i[j]];
}
    NSLog(@"%@",str);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM