User not logged in - login - register
Home Calendar Books School Tool Photo Gallery Message Boards Users Statistics Advertise Site Info
go to bottom | |
 Message Boards » » \n isn't working Page [1]  
kimslackey
All American
7841 Posts
user info
edit post

in java in my string.

any ideas?
the tab works "\t" though

4/10/2006 11:10:22 PM

Novicane
All American
15413 Posts
user info
edit post

\\n

4/10/2006 11:13:29 PM

kimslackey
All American
7841 Posts
user info
edit post

^ sorta, but i don't want the "\n" to appear i want it to go to the next line

4/10/2006 11:18:21 PM

Excoriator
Suspended
10214 Posts
user info
edit post

\n is for wimps. use ascii code

4/10/2006 11:23:17 PM

TGD
All American
8912 Posts
user info
edit post

don't think it makes a difference as far as the spec goes, but what version of Java are you running? ('prompt% java -version' on the command line)

everything in quotes too?

[Edited on April 11, 2006 at 12:18 AM. Reason : ---]

4/11/2006 12:17:48 AM

bous
All American
11215 Posts
user info
edit post

this has to be operator error. and not the programming type of operator.

4/11/2006 12:25:04 AM

skokiaan
All American
26447 Posts
user info
edit post

this is what happens when you get women programmers

4/11/2006 1:32:10 AM

MiniMe_877
All American
4414 Posts
user info
edit post

use this to get the correct line separator:

String newline = System.getProperty("line.separator");


why are you using an embedded newline character in a string anyhow? bad form

[Edited on April 11, 2006 at 10:11 AM. Reason : http://java.sun.com/j2se/1.3/docs/api/java/lang/System.html#getProperties()]

or optionally use
System.out.println("");


[Edited on April 11, 2006 at 10:15 AM. Reason : println]

4/11/2006 10:11:20 AM

Excoriator
Suspended
10214 Posts
user info
edit post

Quote :
"String newline = System.getProperty("line.separator");"


and this is why i hate java. Fifty-five characters to print a motherfkcin newline

since when do you have to initialize a newline for god's sake

[Edited on April 11, 2006 at 3:21 PM. Reason : s]

4/11/2006 3:20:50 PM

MiniMe_877
All American
4414 Posts
user info
edit post

you do it that way for platform portability, which is the major thing Java has going for it. Write once, run anywhere

\n on UNIX/Linux, \r\n on Windows, and \r on Mac

4/11/2006 6:46:43 PM

LimpyNuts
All American
16859 Posts
user info
edit post

0x0A = carriage return
0x0D = line feed

a new line in windows is carriage return+line feed. in linux it's just line feed (a.k.a. EOL -- "end of line") and on an apple machine it's a carriage return. i think it's retarded but thats what it is.

4/11/2006 7:04:20 PM

afripino
All American
11350 Posts
user info
edit post

'\n'

[Edited on April 11, 2006 at 7:24 PM. Reason : new line 'character']

4/11/2006 7:19:45 PM

LimpyNuts
All American
16859 Posts
user info
edit post

\n is character 0x0D, which doesn't produce a new line on all platforms. see ^^^ and ^^.

[Edited on April 11, 2006 at 8:18 PM. Reason : ]

4/11/2006 8:18:12 PM

Shaggy
All American
17820 Posts
user info
edit post

\n has worked without issue for me in both lunix and windows

4/11/2006 8:25:21 PM

scud
All American
10804 Posts
user info
edit post

you should specify Win32

try opening text with \n as line seperator in Notepad.....not pretty.

4/11/2006 8:39:08 PM

Excoriator
Suspended
10214 Posts
user info
edit post

then use wordpad

also, fuck platform portability.

4/11/2006 9:19:57 PM

zorthage
1+1=5
17148 Posts
user info
edit post

Quote :
"also, fuck platform portability."


cause everyone uses the same system

If you dont like it, dont use it

4/11/2006 10:52:55 PM

MiniMe_877
All American
4414 Posts
user info
edit post

#ifdef WIN32
#define NEWLINE "\r\n"
#endif
#ifdef MAC
#define NEWLINE "\r"
#endif
#ifdef UNIX
#define NEWLINE "\n"
#endif

There, thats some multiplatform C/C++ for ya

4/11/2006 11:12:47 PM

skokiaan
All American
26447 Posts
user info
edit post

^ std::endl

4/11/2006 11:24:05 PM

ZeroDegrez
All American
3897 Posts
user info
edit post

Quote :
"why are you using an embedded newline character in a string anyhow? bad form"

Not really.

Unless you are writing a file a user has to read, or a multiline error message (to the console) then it matters. Otherwise, as long as the '\n' is perfectly fine way to save out a newline.

4/11/2006 11:31:41 PM

Excoriator
Suspended
10214 Posts
user info
edit post

why the fuck even bother with a newline if you're not writing a human readable file. and don't give me that delimiting shit - there are plenty of better options for that shit

4/12/2006 8:38:18 AM

qntmfred
retired
40562 Posts
user info
edit post

| all the way!

4/12/2006 9:20:07 AM

eep13850
Starting Lineup
60 Posts
user info
edit post

Are you using this to display in a JTextField. If so, you can only display one line. Change the JTextField to a JTextArea, so you can display multiple lines.(especially if this is for csc116 lab 9).

4/14/2006 12:57:47 AM

 Message Boards » Tech Talk » \n isn't working Page [1]  
go to top | |
Admin Options : move topic | lock topic

© 2024 by The Wolf Web - All Rights Reserved.
The material located at this site is not endorsed, sponsored or provided by or on behalf of North Carolina State University.
Powered by CrazyWeb v2.38 - our disclaimer.