SO Im在創建一些共享代碼時卡在我的項目中。我有一個包含一些字符串的列表。我想過濾這個,然後將過濾後的字符串分開。我已經在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"];
我tryed分裂這樣的:
foreach (string s in TrackTraceDataByLine) {
string[] splitted = s.Split (new char[] { ' ' });
if (s.Length >= referenceNumber.Length) {
if (referenceNumber == splitted [1]) {
dataFilteredOnRef.Add (s);
}
}
}
我可以很快的意識到,我有能力做它而不是分裂在空間上。這是因爲像參考號碼這樣的部分可以包含空格。
@Axarydax看到編輯:) –