views:

56

answers:

3

I want to create a text file, than load it up without any newlines or spaces (This is for a simple RPG). So I want to test for all 3 major OS line separators, and than the current OS'(s?) one. I know I can get the current one using System.getProperty("line.separator"), but how can I get Linux, Mac, and Windows line separators and turn them into a string for Java?

Edit: I need a single character representation of these, because for some reason "\n" doesn't work (Yes I'm on windows).

A: 

there's no "getter" for these, you just need to copy the strings off the internet into your own constants.

Rob Fonseca-Ensor
A: 

Wouldn't you just want to remove all occurrences of \n and \r from your text?

Unless you're using jurassic operating systems, you only have to deal with \r\n and \n.

General information about newline representations on different platforms: http://en.wikipedia.org/wiki/Newline#Representations

birryree
+1  A: 

They are "\n" (Linux and MacOS X), "\r" (MacOS 9 and older) and "\r\n" (Windows).

Just hard-code them - they're not going to change! :-)

Edit: There's no "single character representation" of "\r\n" - it's two characters.

RichieHindle