-3

I'm creating an application where it saves a file according to whats enter into a couple of textboxes. Example: I have a subject textbox which equals "test" and a messagebody textbox which equals "test123", the file saved would look like this:

[Subject]
test
[Body]
test123

There is also a string that equals all the contents of the file. I want to basically open and read the file (already done and working), then write everything between "[Subject]" and "[Body]" to be written to the subject textbox. Also write everything after "[Body]" to the messagebody textbox.

jww
  • 97,681
  • 90
  • 411
  • 885
  • 6
    Is your format of [Subject] ... [Body] absolutely necessary? You could use other formats like XML or even JSON – bit Oct 06 '14 at 03:59
  • 1
    Consider if broadly used file formats JSON, XML are acceptable. Otherwise please show code you have problem with. – Alexei Levenkov Oct 06 '14 at 04:00
  • 1
    Is this the entire file, or is the entire file exactly like that? If either of those is yes, you can just do this by reading specific line numbers rather than dealing with regex. – IllusiveBrian Oct 06 '14 at 04:00
  • Possible duplicate of [C# Splitting Strings?](http://stackoverflow.com/questions/7559121/c-sharp-splitting-strings) – jww Oct 06 '14 at 04:01

1 Answers1

0

You can just do this:

var arr = txt.Replace("[Subject]","").Split(new string[]{"[Body]"}),
subject = arr[0],
body = arr[1];
Amit Joki
  • 58,320
  • 7
  • 77
  • 95