views:

75

answers:

3

What is the equivalent of C#'s \n and Visual Basic's vbCRLF or vbNewLine in Delphi Prism? Do I have to use Environment.NewLine?

+4  A: 

Environment.NewLine is actually the best thing to use, as it is supposed to be platform independent. This guidance goes for C# as well, by the way.

Michael Bray
If exchanging data with some other party, platform independent control codes determined by the runtime may not be appropriate. Better to be explicit in such cases. Ironically this is perhaps even more important if NOT exchanging data: platform independence is not as important is straightforward consistency - a Prism (i.e. .NET) app running on multiple platforms with different NewLine expectations is potentially going to get confused when reading files created by "itself" when running on some platforms versus others !!!
Deltics
A: 

MyString := 'One'#13#10'Two'; would be the equivalent of c#'s "One\r\nTwo".

Ck
A: 

The appropriate new line character is not a question of runtime platform or language choice, it is a question of the source (or intended recipient) of the output file. If the file is entirely for private use by an application (only ever read/written by the app) then you can use whatever character you like to delimit lines.

If you need to exchange the file with some party or process outside of the application itself then the needs of that other party may well dictate what you should expect (and are expected) to use as the new line character.

To answer the actual question as put however, the equivalent of vbCRLF is (as a literal value) #13#10 and the equivalent of vbNewLine would be #10 (#13 is the char code for CR and #10 for LF).

Deltics