Welcome, Guest. Please login or register.

Author Topic: More elegant way of removing/ignoring \n  (Read 2448 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Trev

  • Hero Member
  • *****
  • Join Date: May 2003
  • Posts: 1550
  • Country: 00
    • Show all replies
Re: More elegant way of removing/ignoring \n
« on: May 28, 2009, 07:09:18 AM »
It should also be noted that the value of '\n' is entirely library-dependent, and '\n' can and should be converted to an environment-specific newline sequence by the library. Technically, a text stream written on system A can't be safely read on system B until a low-level line ending conversion has taken place. Thankfully, the conversion is typically 0x0D0A <-> 0x0A, but you can't take it for granted, particularly when you know the text stream was created on a non-ASCII source system.

As noted, '\n' in the C standard library translates to CR+LF in the text stream in DOS/Windows and LF in AmigaDOS.

EDIT: If you're looking to do strict ASCII conversion or scanning, then "\x0d\x0a" for "\r\n" and "\x0a" for "\n" might be "safer."

Wikipedia's Newline article covers this in pretty good detail.
« Last Edit: May 28, 2009, 07:16:38 AM by Trev »