Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 从字符串到数组的内容_Objective C - Fatal编程技术网

Objective c 从字符串到数组的内容

Objective c 从字符串到数组的内容,objective-c,Objective C,我有一个字符串需要排序(不是从高到低),该字符串设置为用逗号分隔每个数字,每三个数字后面有一个空格: 26249614922523061049,9968353132 860,9959587920 4717,9943863427 807,9967243688 1382,9937865117 1088,9914810482 95,9967711274 5,992000000000 3310,9925639438 75,99157217334 1923,9929678736 48,9911880634

我有一个字符串需要排序(不是从高到低),该字符串设置为用逗号分隔每个数字,每三个数字后面有一个空格:

26249614922523061049,9968353132 860,9959587920 4717,9943863427 807,9967243688 1382,9937865117 1088,9914810482 95,9967711274 5,992000000000 3310,9925639438 75,99157217334 1923,9929678736 48,99118806349 133,9935055345 563,9921098356 3410,9917805574,9962821143 2504,9914821240,992000000000,1943193983,9916825678 17826,9913768252 1129,9917249030 5393,9914082021 338120137201472 28501944-1,-1-1,-1-1,-1 45093988 38633987 26324148 57904105-1,-1-1


我需要为3个数字中的每一个创建某种关联。有点像二维数组和字典。有什么建议吗?

先用空格分割字符串,然后用逗号分割每个被分割的项目,就像下面的算法一样

threeItems = split main string with white space
for each itemString in threeItems
  threeItem = split itemString with comma
  do something with threeItem
end for

假设字符串保存在名为“myNumbers”的变量中,请执行以下操作:

NSString *myNumbers = @"26,2496,1492252306 1049,99,68353132 860,99,59587920 4717,99,43863427 807,99,67243688 1382,99,37865117 1088,99,14810482 95,99,67711274 5,99,200000000 3310,99,25639438 75,99,157217334 1923,99,29678736 48,99,118806349 133,99,35055345 563,99,21098356 3410,99,17805574 47,99,62821143 2504,99,14821240 5,99,200000000 3076,99,19425499 474,99,31321799 3983,99,16825678 17826,99,13768252 1129,99,17249030 5393,99,14082021 338,120,137201472 2850,1944 -1,-1 -1,-1 -1,-1 -1,-1 4509,3988 3863,3987 2632,4148 5790,4105 -1,-1 -1,-1";

NSArray *triples = [myNumbers componentsSeparatedByString:@" "];

NSMutableArray *matrix = [[NSMutableArray alloc] init];

for (NSString *triple in triples) {
    [matrix addObject:[triple componentsSeparatedByString:@","]];
}

NSLog(@"matrix: %@", matrix);
[matrix release];

对不起,我真的不明白问题是什么。我不完全确定你想要实现什么,但你可以将“做点什么”部分的项目索引到2D数组中,然后按照你想要的方式对它们进行排序。根据您对它们的排序方式,可能有更好的方法对它们进行索引。