我有一个可以包含一个或多个字符串的数组。这是我的意见:
51403423 0001051629 1302130622 TOMTOM101订单51403423-3-179178687:ontvangen
51403423 0001051629 1302130644 TOMTOM241订单51403423-3-179178687:gestart
51403423 0001051629 1302130645 TOMTOM241订单51403423-3-179178687:geschatte aankomst 7:33,57 km op bes
51403423 0001051629 1302130937 TOMTOM241订单51403423-3-179178687:gestart
51403423 0001051629 1302130951 TOMTOM249订单51403423-3-179178687:voltooid
这些字符串是从像这样的大文本文件中过滤掉的:
NSData *tmpData = [NSData dataWithContentsOfURL:[NSURL URLWithString:trackTraceFileUrlName] ];
NSLog(@"%@",trackTraceFileUrlName);
//convert data to string
NSString *tmpString = [[NSString alloc] initWithData:tmpData encoding:NSUTF8StringEncoding];
NSArray *piecesArray = [tmpString componentsSeparatedByString:@"\n"];
NSMutableArray *trackTraceContent = [NSMutableArray arrayWithArray:piecesArray];
NSLog(@"%@",trackTraceContent);
/*Filtering array for referance*/
NSPredicate *findStringWithReference = [NSPredicate predicateWithFormat:@"SELF contains[c] %@",cRText.text];
NSArray *trackTraceContentFiltered = [trackTraceContent filteredArrayUsingPredicate:findStringWithReference];
/*Filtering array for Collected status*/
NSPredicate *findStringWithStatusCollected = [NSPredicate predicateWithFormat:@"SELF contains[c] 'TOMTOM229'"];
NSArray *filteredArrayOnStatusCollected = [trackTraceContentFiltered filteredArrayUsingPredicate:findStringWithStatusCollected]
;
过滤文本文件的结果将是包含过滤对象的Array。这将是这样的:
filteredArrayOnStatusCollected:“51403423 0001051629 1302121101 TOMTOM229订单51403423-2-477100555:voltooid“
现在我想要插入这个对象,这样我就可以将1302121101所在的部分放入标签中。我该怎么做?
答案 0 :(得分:0)
如果对象是一个字符串,并且它全部由空格分隔,则可以通过调用
获取“标记”的数组NSArray *components = [string componentsSeparatedByString:@" "];
然后,如果您试图访问这些组件的静态索引,或者您正在专门查找该文本,那么找出具体如何1302121101
完全依赖
答案 1 :(得分:0)
theLable.text = [[theString componentsSeparatedBySring:@" "] objectAtIndex:2];
,其中theLable为UILable*
,字符串为NSString*
。