I'd like to use text only from a subtitle for further processing.
So, opening a srt file would load this
1
00:00:10,500 --> 00:00:13,000
Elephant's Dream
2
00:00:15,000 --> 00:00:18,000
At the left we can see...
Then, after stripping/extracting, the result would be
Elephant's Dream
At the left we can see...
I want to strip out all the numbering and timecode, so the output would consist only of plain text in the exact same order as the original subtitle, and store the result in a variable for further processing.
public void open_file()
{
JFileChooser filechooser = new JFileChooser();
filechooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
int i = filechooser.showOpenDialog(this);
if (i == filechooser.CANCEL_OPTION)
return;
File OpenFile = filechooser.getSelectedFile();
if (OpenFile == null || OpenFile.getName().equals(""))
{
JOptionPane.showMessageDialog(this, "choose file", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
try {
BufferedReader bufferedreader = new BufferedReader(new FileReader(BukaFile));
StringBuffer stringbuffer = new StringBuffer();
String Row;
while ((Row = bufferedreader.readLine()) != null) stringbuffer.append(Row+"\n");
textArea.setText(stringbuffer.toString());
String SubText = textArea.getText();
} catch (FileNotFoundException ex) {
JOptionPane.showMessageDialog(null, "File not found" + ex);
} catch (IOException ex)
{
JOptionPane.showMessageDialog(null, "IO Error"+ ex);
}
}
I've made a method (as above) to open and load an existing srt file and put it into a String (named SubText above) variable.
To extract those texts, all I know is that I have to use either numberings, timecodes, and blank space for start point and end point, but I have no idea on how to code for detecting those numberings and timecodes in the text.
How should I accomplish this in java? I'm using Netbeans, by the way.