tob*_*enn 1 parsing objective-c nsstring
我正在将*.srt字幕文件读入NSString.此字符串的内容如下所示:
1
00:00:20,000 --> 00:00:24,400
Altocumulus clouds occur between six thousand
2
00:00:24,600 --> 00:00:27,800
and twenty thousand feet above ground level.
Run Code Online (Sandbox Code Playgroud)
我正在寻找一个优雅的解决方案,将此字符串拆分为NSArray,其中每个元素包含与一个特定字幕 - "框架"相关的信息,例如,第0个元素将如下所示:
1
00:00:20,000 --> 00:00:24,400
Altocumulus clouds occur between six thousand
Run Code Online (Sandbox Code Playgroud)
任何想法如何以优雅的方式完成这项任务?我尝试使用该方法拆分原始字符串
[string componentsSeparatedByString:@"\n\n"];
Run Code Online (Sandbox Code Playgroud)
但是这种方法无法检测到空行.
谢谢你的帮助!
TOBI
如果[string componentsSeparatedByString:@"\n\n"]不起作用,那么有两种可能性:
您的文件包含MSDOS样式的换行符\r\n.所以尝试分裂@"\r\n\r\n".
你所谓的空白行包含空格或制表符.您可以使用shell从shell中进行检查cat -e.