如何在Objective c中为iphone创建一个字符串数组 [英] How to create an Array of Strings in Objective c for iphone

查看:83
本文介绍了如何在Objective c中为iphone创建一个字符串数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



如果这个数组可以随机化,我可以随机选择一个字符串数组。选择第一个x字符串,这将工作正常。



我试图使用这样的代码

  NSString * statements [9]; 
statements [0] = @hello;

这似乎工作,但数组似乎充满了垃圾数据。



有人可以帮助我在正确的方向。

解决方案

你想要一个包含九个字符串的数组吗?

  [NSArray arrayWithObjects:@1,@2 ,@3,4,5,6,7,8,9,nil] 


I'm trying to create an array of strings that can be randomized and limited to a certain x number of strings.

If the array could be randomized I could pick the first x strings and that would work fine.

I'm trying to use code like this currently

NSString *statements[9];
statements[0] = @"hello";

This seems to work but the array seems to be full of rubbish data.

Can someone help me in the right direction. (is the memory allocation being done in the wrong way?

Thanks

解决方案

Do you want an array with nine strings in it?

[NSArray arrayWithObjects: @"1", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9", nil]

这篇关于如何在Objective c中为iphone创建一个字符串数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆