Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newline Characters

Status
Not open for further replies.

crmayer

Programmer
Nov 22, 2002
280
US
I am trying to print something out on our check stubs. I have a text field created and I want to print order # and invoice # in it then return and print another one if there is one. What is the BEST practice to get a newline character in there? EXAMPLE
Order # INVOICE #
123456 7891011
234567 89101112

Currently I am going through a loop and sending this
comment = comment.append(Setquery.getString("order_id", null) + " " + Setquery.getString("external_invoiceno", " ") + "\n");

I am just not sure that the "\n" is the best way to do this for all systems, printers, and platforms..... Is there a better way to send a newline or carriage-return the "\n" or is that the best practice?
For some reason when I was testing this in my development environment, it was working fine. The I moved it over to live and this is what I got:

123456 7891011?234567 89101112?

I am pretty sure that the "?" is the newline symbol, but is there some reason that one printer/OS reads it OK and another does not?
 
Use the folowing call to get current system line separator :
Code:
System.getProperty("line.separator");

Water is not bad as long as it remains outside human body ;-)
 
There is also a newLine() method you can use which is platform independant.

The '\n' literal usually only works for Windows platforms.
 
I might try that newLine() method. Currently I am using the System.getProperty("line.separator"); which seems to work on any platform, but it is still printing out the "  " after the invoice number....
 
@metheus:
The '\n' literal usually only works for Windows platforms.
No.
Works on linux/unix-like systems.
I don't know about mac, but heard about '\r'.

@crmayer: you should use a hex-editor, to find out what code you produce after the invoice-number.
AFAIK windows uses "\n\r" normally as lineseparator, but in the end it's up to the application, to handle linefeeds.

notepad will not understand simple "\n"s but wordpad will.

seeking a job as java-programmer in Berlin:
 
\n" (or linefeed) is the usual eol character for Unix/Linux.
"\r" (or carriage return) is the usual eol char for Mac.
"\r\n" is the usual eol sequence for Dos / Windoze.

I suspect that you are generating just "\n" as you suggest and trying to read it in windoze (notepad or the like). They will not like it.
For windoze you need to append "\r" AND "\n" in that sequence and all will be fine.
BTW: Word for Windoze is quite good at dealing with Unix style eol markers.



Trojan.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top