在iPhone中解析数组元素 [英] parsing array elements in iPhone
问题描述
NSBundle *bundle = [NSBundle mainBundle];
NSString *pthpath = [bundle pathForResource:@"path" ofType:@"txt"];
NSString *content = [NSString stringWithContentsOfFile:pthpath encoding:NSUTF8StringEncoding error:nil];
array=[[NSArray alloc ]init];
array = [content componentsSeparatedByString:@"~"];
=====================================================================
这里的内容是:
87,348〜51,347〜135,132〜182,133〜268,346〜236,347〜159,168〜87,347 @ 118,298〜115,297〜200,298〜189,266〜128,265〜117,299 @ 222,352〜268,353〜264,340〜219,342〜225,355 @ 186,262〜199,299〜212,297〜195,257〜188
87,348~51,347~135,132~182,133~268,346~236,347~159,168~87,347@118,298~115,297~200,298~189,266~128,265~117,299@222,352~268,353~264,340~219,342~225,355@186,262~199,299~212,297~195,257~188,260
和数组是:
"87,348", "51,347", "135,132", "182,133", "268,346", "236,347", "159,168", "87,347 @ 118,298", "115,297", "200,298", "189,266", "128,265", "117,299 @ 222,352", "268,353", "264,340", "219,342", "225,355 @ 186,262", "199,299", "212,297", "195,257", "188,260"
"87,348", "51,347", "135,132", "182,133", "268,346", "236,347", "159,168", "87,347@118,298", "115,297", "200,298", "189,266", "128,265", "117,299@222,352", "268,353", "264,340", "219,342", "225,355@186,262", "199,299", "212,297", "195,257", "188,260"
但是我想通过使用@解析来再次创建一个数组.请帮帮我...........
But I want to again create an array by parsing with @. Please help me out...........
推荐答案
如果我正确理解了您的问题,我认为从以下代码中您可能会有所了解
I think from following code you may get some idea, if I understood your question correctly,
NSMutableArray *resultArray = [[NSMutableArray alloc] initWithCapacity:1];
NSArray *tempArray1 = nil;
NSArray *tempArray2 = nil;
NSString *content = @"87,348~51,347~135,132~182,133~268,346~236,347~159,168~87,347@118,298~115,297~200,298~189,266~128,265~117,299@222,352~268,353~264,340~219,342~225,355@186,262~199,299~212,297~195,257~188,260";
tempArray1 = [content componentsSeparatedByString:@"@"];
for(NSString *string in tempArray1)
{
tempArray2 = [string componentsSeparatedByString:@"~"];
[resultArray addObjectsFromArray:tempArray2];
}
NSLog(@"ResultArray :%@", resultArray);
这篇关于在iPhone中解析数组元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!