在Objective-C中创建二维数组 [英] Creating a two dimensional array in Objective-C

查看:102
本文介绍了在Objective-C中创建二维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Objective-C中声明二维数组的最简单方法是什么?我正在从网站的文本文件中读取数字矩阵,并希望将数据放入3x3矩阵中.

Whats the easiest way to declare a two dimensional array in Objective-C? I am reading an matrix of numbers from a text file from a website and want to take the data and place it into a 3x3 matrix.

将URL读入字符串后,我将创建一个NSArray并使用componentsSeparatedByString方法剥离回车换行符并创建每个单独的行.然后,我获得新数组中的行数计数,以获取每一行的单个值.这将为mw提供一个包含字符串的数组,而不是一行包含三个单独值的行.我只需要能够获取这些值并创建一个二维数组.

Once I read the URL into a string, I create an NSArray and use the componentsSeparatedByString method to strip of the carriage return line feed and create each individual row. I then get the count of the number of lines in the new array to get the individual values at each row. This will give mw an array with a string of characters, not a row of three individual values. I just need to be able to take these values and create a two dimensional array.

推荐答案

如果不需要成为对象,则可以使用:

If it doesn't need to be an object you can use:

float matrix[3][3];

定义一个3x3的浮点数数组.

to define a 3x3 array of floats.

这篇关于在Objective-C中创建二维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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