Get a new line in random encoding

I send several letters to people in different cultures. Data comes from the file in the appropriate encoding. However, I need to read the first few lines to process them (get the topic, etc.), so I:

var lines = File.ReadAllLines(filename, encoding); ... read first few lines up to blank... lines = String.Join(newline, lines.skip(lineNum)); 

However, I do not know what to do to get the corresponding newline value. It is different for each encoding, and I cannot use Environment.NewLine, because I need a new line for the specific encoding of the email recipient, and not the encoding of the web server.

+4
source share
2 answers

You are still dealing with text, so you don’t have to worry about encoding (converting to / from binary representations of character data). What you need to potentially worry about is the different representations of the "new line" in terms of characters.

It's not clear what you use to send mail in the end - I expect that everything you use can still be parsed for you. However, RFC 822 defines strings as separated by CRLF ("\ r \ n"), so I would use this.

Of course, if you also submit an HTML version of the text, it will still contain HTML tags to separate lines / paragraphs.

+4
source

You may need to read it line by line so that you don’t worry much about the encoding problem:

  while ((line = File.ReadLine()) != null) { if (line != String.Empty) lines += line + Environment.NewLine; } 
+1
source

All Articles