0

I have a FlowDocument in a RichTextBox that looks like this:

INT. LOCATION - DAY 

Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
Nulla id risus odio. Donec dictum viverra rutrum. 
Quisque malesuada velit sed augue interdum vehicula. 

                     CHARACTER NAME
                Mauris sit amet nisi varius 
                velit luctus vestibulum tempor egestas augue. 
                Quisque viverra vulputate iaculis. 

Nam sit amet risus at justo feugiat consequat a non ex. Morbi scelerisque libero quam, 
eget imperdiet justo iaculis sed.

EXT. LOCATION - NIGHT

Morbi cursus dictum tempor. Phasellus mattis at massa non porta. 
Etiam ac pellentesque tortor, sit amet facilisis massa. 

                       CHARACTER NAME
                 Aenean viverra convallis dolor, 
                 quis venenatis odio tempus a. 

Sed vel aliquet arcu, in tincidunt est. 

INT. LOCATION - NIGHT

Etiam sit amet tristique sapien. 

Now I need to split this text up into sections each time INT. or EXT. starts to use later on in the app. What's the best way to do this?

this is how I load the textfile into a richTextBox:

private void Button_Click(object sender, RoutedEventArgs e)
{

        openFile.InitialDirectory = @"C:\";
        openFile.Filter = "Text files (*.txt)|*.txt|All Files (*.*)|*.*";
        openFile.RestoreDirectory = true;
        openFile.Title = "Select Script";

        if (openFile.ShowDialog() == true)
        {
            string originalfilename = System.IO.Path.GetFullPath(openFile.FileName);

            TextRange range;
            FileStream fStream;

            if (openFile.CheckFileExists)
            {
                range = new TextRange(rtfMain.Document.ContentStart, rtfMain.Document.ContentEnd);
                fStream = new FileStream(originalfilename, System.IO.FileMode.OpenOrCreate);
                range.Load(fStream, DataFormats.Text);
                fStream.Close();
            }
      }
}
Phil
  • 561
  • 2
  • 16
  • 29
  • Assuming that someone is entering the data you should make the user start a new section whenever they want to change scenes. (This looks like a script/play). You can have a user add a scene where they enter the scene info and then add the scene text. These can all be added as sections to the FlowDocument as a whole – JNYRanger Jun 07 '15 at 21:04
  • It's actually to analyse a script. It's already been loaded into a richtextbox and needs to be split up into sections. – Phil Jun 07 '15 at 21:10
  • Are the scene headings always in the same pattern using INT. / EXT. - (some location) - DAY / NIGHT, or are there more possibilities? – JNYRanger Jun 07 '15 at 21:12
  • It's always INT. or EXT or I/E sometimes preceded by a number – Phil Jun 07 '15 at 21:26
  • Can you show us how this exists in a FlowDocument, or if you're trying to generate one from the script text only. – JNYRanger Jun 07 '15 at 21:39
  • I've just added in the question the function of how I load the text into the RIchTextBox. Hope that helps to understand what I would like to achieve – Phil Jun 07 '15 at 21:47

1 Answers1

0

As FlowDocument syntax is so close to HTML, I would split the solutions up using an HTML parser, see: https://softwarerecs.stackexchange.com/questions/10773/c-library-for-parsing-html. You could also experiment with any other XML parser.

Whatever you do, don't use regular expressions, as that way leads to madness, as evidenced by the most popular post on StackOverflow: RegEx match open tags except XHTML self-contained tags.

Community
  • 1
  • 1
Contango
  • 76,540
  • 58
  • 260
  • 305