Do we have a carriage return & new line platform-specific constant?

Different platforms and technologies use different carriage return strings. Some use \r, some use \n, some use both.

Is there some constant in Haxe std for this?

1 Like

I don’t think so.
It depends on a runtime environment. Or rather on an environment, where you want your output to be read in.
And some runtimes may not have it strictly defined (e.g. javascript in browsers).
You can use something like this on sys targets:

switch(Sys.systemName()) {
  case "Mac": "\r";
  case "Linux": "\n";
  case _: "\r\n";

I see. Do you think it would be useful to have a haxelib that treats all combinations of this? It’s easy to determine what browser you’re running in, and combine that with systemName if required.

Having a haxelib for such a small thing is rather silly though. Perhaps this could be integrated in an existing library.

I’m not sure how safe that approach is, it’s possible to encounter files with only \n even if you’re on Windows. Might be better to have a regex like ~/((\r\n)|\r|\n)/ that matches all possibilities.

1 Like

You can use Strings.NEW_LINE of haxe-strings (6.0.3)


Niiiiiiiiiiiifty @seb :smiley: Thank you so much! :slight_smile: You guys here are so much more awesome than the, sorry to say it, trolls at Sack Exchange (typo intended).

To clarify: I’ve often asked questions on SO/SE just to get bashed with pointless comments, patronizing or overly-zealous moderators. That being said, there’s of course plenty of nice people there as well, but the overall feeling I get when I think about posting a question there is a mix of anxiety and other not-so-pleasant memories.