私はプログラミングとstackoverflowを初めて使い、目標cを学ぶことから始めました。テキストファイルのトークン化と解析(意思決定リストASCIIテキストファイルの編集)目的C
深いところで、私は知っています。
私はedlファイルを解析する最良の方法を試してみようとしています。 基本的に100KB以下のASCIIテキストファイルです。ここ は、典型的なcmx3600 EDLの構造である:
TITLE: EP1 FINAL.EDL SECTION2
FCM: NON-DROP FRAME
001 A199_C00 V C 20:38:24:15 20:38:26:04 10:30:00:02 10:30:01:16
* SOURCE FILE: A199_C008_0915AH_001
002 A199_C00 V C 20:34:48:17 20:34:51:23 10:30:01:16 10:30:04:22
* SOURCE FILE: A199_C007_0915VE_001
私は/配列すなわちフィールドに各要素を解析したり、スキャンするための最良の方法をうまくしようとしている、
editNum = 001
tapeName = A199_C00
channel = V
Operation = C
sourceIn = 20:38:24:15
sourceOut = 20:38:26:04
recIn = 10:30:00:02
recOut = 10:30:01:16
sourceFile = A199_C008_0915AH_001
これは私ですこれまでコード:
-(IBAction)importEdl:(id)sender {
//defines an Array of allowed file types with file extension ".EDL and .edl"
NSOpenPanel *myPanel = [NSOpenPanel openPanel];
NSArray *fileTypes = [NSArray arrayWithObjects:@"EDL", @"edl", nil];
myPanel.allowedFileTypes = fileTypes;
myPanel.allowsMultipleSelection = NO;
if ([myPanel runModal] == NSOKButton)
{
NSString *theFilePath = [myPanel filename];
NSString *psEdlFile = [NSString stringWithContentsOfFile:theFilePath encoding:NSASCIIStringEncoding error:NULL];
// Reads the file as one string. EDL's are simple ASCII text files of roughly 50KB.
NSArray *psEdlLines = [psEdlFile componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
// Separates the data into lines.
if([psEdlLines count] == 0)
{
NSLog(@"Error!");
} //prints error if EDL file has no events.
NSUInteger count;
int i;
for (i = 0, count = [psEdlLines count]; i < count; i = i + 1)
{
NSString *lineStrings = [psEdlLines objectAtIndex:i];
NSLog(@"Line %d is %@",i+1,lineStrings);
//NSArray *linesEnum = [psEdlLines objectAtIndex:i];
//this creates an array of lines
//NSLog(@"index is: %d %@",i, linesEnum);
}
}
}
@end
出力は次のようになります。
2012-03-20 15:22:08.956 TestProgram[412:903] Line 1 is TITLE: EP1 FINAL.EDL SECTION2
2012-03-20 15:22:08.957 TestProgram[412:903] Line 2 is FCM: NON-DROP FRAME
2012-03-20 15:22:08.957 TestProgram[412:903] Line 3 is 001 A199_C00 V C 20:38:24:15 20:38:26:04 10:30:00:02 10:30:01:16
2012-03-20 15:22:08.957 TestProgram[412:903] Line 4 is * SOURCE FILE: A199_C008_0915AH_001
2012-03-20 15:22:08.957 TestProgram[412:903] Line 5 is 002 A199_C00 V C 20:34:48:17 20:34:51:23 10:30:01:16 10:30:04:22
2012-03-20 15:22:08.957 TestProgram[412:903] Line 6 is * SOURCE FILE: A199_C007_0915VE_001
2012-03-20 15:22:08.957 TestProgram[412:903] Line 7 is 003 A199_C00 V C 20:42:32:01 20:42:35:19 10:30:04:22 10:30:08:15
2012-03-20 15:22:08.957 TestProgram[412:903] Line 8 is * SOURCE FILE: A199_C009_0915RX_001
2012-03-20 15:22:08.957 TestProgram[412:903] Line 9 is
2012-03-20 15:22:08.958 TestProgram[412:903] Line 10 is
私はあなたが見ることができるほど遠くはありません。 アイデアをいただければ幸いです。 ありがとうございます、 ピート。
構文解析を行っている場合は、BNF文法を使用してください。 1つを構築し、それを使用することは非常に良い学習の練習になります。 –
[ParseKit](http://www.parsekit.com/)をご覧ください。 –
また、NSScannerは、あなたがCocoaを初めて使用していて、ネイティブフレームワークに慣れ親しんでいる場合に使用します。 – FluffulousChimp