I am reading a *.srt subtitle file into a NSString. The content of this string looks like this:
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.
I am looking for an elegant solution to split this string into an NSArray in which each element contains the information which is related to one particular subtitle-“frame”, e.g. the zeroth element would look like this:
1
00:00:20,000 --> 00:00:24,400
Altocumulus clouds occur between six thousand
Any ideas how to accomplish this task in an elegant manner? I tried splitting the original string using the method
[string componentsSeparatedByString:@"\n\n"];
but this method fails to detect the blank lines..
Thanks for your help!
tobi
If
[string componentsSeparatedByString:@"\n\n"]doesn’t work, then there are two possibilities:Your file contains MSDOS-style line breaks, which are
\r\n. So try splitting on@"\r\n\r\n".Your supposedly blank lines contain spaces or tabs. You can check this from the shell using
cat -e.