Question

Coding in Objective-C, I'm appending text to a NSTextView object named subCap in my code like so:

[[[_subCAP textStorage] mutableString]appendString:[NSString stringWithFormat:@"%@", subcapLine]];

subcapLine will have two timecode values such as: "01:00:00:00 01:00:01:00" separated by a single space, then a newline (\n) character, then a string like "ONC314_001_001" followed by two newline chars (\n\n).

The end result will create a list similar to:

01:00:00:00 01:00:01:00
ONC314_001_001

01:00:01:00 01:00:02:00
ONC314_001_002

01:00:02:00 01:00:03:00
ONC314_001_003

etc, etc, etc.

It's a sub caption file for placing text (the ONC314 lines) at appropriate times in a video file, as indicated by the timecodes.

However, I've determined that there is an odd set of circumstances where a timecode pair could be the same as the previous timecode pair, and if that happens, I want to skip appending that line.

So, my question is, given that the timecodes are always 11 chars apiece, separated by a space, can anybody think of a way I can easily grab the prior TC pair and compare it to my current pair in the subcapLine I'm preparing to append? The problem is the text of the sub caption could be random lengths. In my example they're the same, but that isn't always the case.

If I need to check prior to compiling my subcapLine, I can do that too, but I just thought it might be more slick to use a range of some sort to grab the prior pair of TCs from the last-written line in the NSTextView object and compare (again, using a range?) against the TCs in the line I'm about to append?

Thoughts and suggestions much appreciated.

Chris Conlee

Was it helpful?

Solution

When you add a timecode store the length of the text field string just before you add the timecode so you will have the offset to the timecode you are about to add.

Then before adding a new timecode you could simply use the previous offset you stored to extract the substring and do a string comparison and see if the timecodes are identical.

This should allow you to always have an offset to the previous timecode regardless of the length of the subtitles.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top