Supposing you need to use Java to do it... A line break is represented as the character combination '\n', so if you were to remove these from the text it'd be a single line, right? Have you written any code that attempts to do this? Can we see it?
Originally posted by Carl Pettersson: A line break is represented as the character combination '\n'. . .
Not quite. That is operating-system dependent. '\n' is a char literal for the linefeed character (0x000a) commonly called newline. There is also the carriage return character (0x000d, I think) which can be represented by the '\r' char literal.
As far as I remember, Windows uses "\r\n" for line ends, *nix (Unix, Linux, etc) uses '\n' and OS/X (Mac) uses '\r'.
Also what appears as the 1st argument to String#replaceAll is a regular expression as a String. Go through the Java Tutorial about regular expressions, and you should find it quite easy to work out how to create a regular expression which matches line-end characters. Find the JFlex manual; it has a comprehensive list of potential line-end characters in. There does not (unfortunately) appear to be a Character#isLineEnd method.
You can find the line-end combination for your computer with the System#getProperty method; I think it is called "line.separator", but you can get an array or Properties with the System#getProperties method and iterate through the array to get the names and check whether that is correct. You will have to cast each char to an int to be able to see their values, otherwise the line end looks like this:
Are these multiple lines in a single String object? If so, use a StringTokenizer with '\n' as the delimiter to break the string into three lines and then concatinate them together. (String s1 += strToken.nextToken())
Bhaskar Rao: StringTokenizer is legacy code: don't use it. Use String#split instead. Use a StringBuilder not String + String for multiple concatenation. And you obviously didn't read what I said about line terminators.
Ganesan did read it, which is why he got the program to work. Well done. It was '\n\r' however, was it? Good thing you checked.
Originally posted by Campbell Ritchie: It was '\n\r' however, was it? Good thing you checked. ;)
Actually, the Windows standard line separator is "\r\n"--a carriage-return followed by a linefeed. However, there's nothing to prevent a file on a Windows machine from having Unix- or Mac-style line separators in it. In fact, you should always assume, no matter what platform you're running on, that the file you're reading can have any style of line separator, or even a mixture of all three styles. A regex like "\r\n?|\n" will match a platform-neutral line separator. But for this task, since you're just getting rid of the line separators anyway, all you need to do is match any number of either of the two characters:
By the way, Campbell, Mac OSX is based on Unix, so its standard line separator is '\n'; it's older MacOS's that use '\r'.