0

I have a file with the following format

-----------------------------------
File: test.cs
Some Text Here 
http:\\link

   Comment #1

   Comment #2

   Comment #X

-----------------------------------

I have the following class:

public class TextFile
{
    public string File;
    public string Description;
    public string Link;
    public List<string> Comments;
}

So far, I am able to grab all the text between the "-" lines, and have them stored in a local string buffer. Now, I am trying to parse that string buffer into the TextFile class. The issue I have is that the Comments can contain new line characters, so I can't simply split the buffer, and then parse the string array.

user2970916
  • 1,146
  • 3
  • 15
  • 37
  • It's a bit difficult; if a comment can contain newline characters, how would you know where the comments ends; is there a certain terminal symbol? Or is every line belonging to the comment indented by 3 characters, as shown in the example? – Codor Feb 10 '17 at 15:59
  • Don't split lines, split keywords ("Comment") ==> then the newline characters aren't a problem anymore –  Feb 10 '17 at 16:01
  • @Codor yes it does look like each comment is indented by 2 characters. – user2970916 Feb 10 '17 at 16:04
  • So a comment can't contain the phrase " Comment #N" and never will? – CodeCaster Feb 10 '17 at 16:04
  • The comments actually don't start with "Comment", I just put that in there for simplicity sake. – user2970916 Feb 10 '17 at 16:06
  • 1
    Yeah so you need to define a pattern and implement that. Start by showing the actual pattern in your question. If each new comment is prepended by two spaces, the same question remains: a comment can't _contain_ a newline followed by two spaces (even though you show three)? – CodeCaster Feb 10 '17 at 16:08
  • How are you delineating between comments? You need someway to know when a new comment begins. – gunnerone Feb 10 '17 at 16:10
  • It's exactly like CodeCaster mentioned, you have to set a exact pattern for your informations and read like you have set your pattern, that's the only way to handly things like this –  Feb 10 '17 at 16:14
  • This is a file that gets exported, so I don't have much control over the format of it. My snippet shows 3 spaces because I manually entered that information. But I can control how the comments are formatted, so I can prevent users from entering a comment followed by a new line and 2 spaces. – user2970916 Feb 10 '17 at 16:15

0 Answers0