所以我在创建一些共享代码时坚持我的项目。我有一个包含一些字符串的列表。我想过滤它,然后在位置上拆分过滤后的字符串。我已经在objective-c中完成了这个,但我不知道如何在c#中做到这一点。
Objective-c 是这样的:
NSPredicate *findStringWithStatusPlanned = [NSPredicate predicateWithFormat:@"SELF contains[c] 'TOMTOM101'"];
NSArray *filteredArrayOnStatusPlanned = [trackTraceContentFiltered filteredArrayUsingPredicate:findStringWithStatusPlanned];
NSLog(@"%@",filteredArrayOnStatusPlanned);
plannedStatusCompleet = [filteredArrayOnStatusPlanned lastObject];
janssenRef = [plannedStatusCompleet substringWithRange:NSMakeRange(0, 8)];
clientRef = [plannedStatusCompleet substringWithRange:NSMakeRange(9, 15)];
dateReceived = [plannedStatusCompleet substringWithRange:NSMakeRange(25, 10)];
tomTomCode = [plannedStatusCompleet substringWithRange:NSMakeRange(36, 9)];
orderText = [plannedStatusCompleet substringWithRange:NSMakeRange(47, 59)];
podFileName = [plannedStatusCompleet substringWithRange:NSMakeRange(113, 19)];
Plannedidentifier = [plannedStatusCompleet substringWithRange:NSMakeRange(62, 1)];
NSLog(@"Planid:%@",Plannedidentifier);
NSArray *cutContentPlannedStatus = [NSArray arrayWithObjects:janssenRef,clientRef,dateReceived,tomTomCode,orderText,podFileName,Plannedidentifier,nil];
[[NSUserDefaults standardUserDefaults] setObject:cutContentPlannedStatus forKey:@"plannedData"];
我试图这样拆分:
foreach (string s in TrackTraceDataByLine) {
string[] splitted = s.Split (new char[] { ' ' });
if (s.Length >= referenceNumber.Length) {
if (referenceNumber == splitted [1]) {
dataFilteredOnRef.Add (s);
}
}
}
我可以很快意识到我必须按位置而不是按空间拆分。这是因为某些部分(如参考编号)可能包含空格。