I do not want to hard code every possible line separator. Is there a way to find an ENTER in a string.
Which one would be better - solving with regular expression or the one above? Won't the regular expression solution un-necessary load the classes?
Henry Wong wrote:
Which one would be better - solving with regular expression or the one above? Won't the regular expression solution un-necessary load the classes?
The one above IS a regex based solution. The replaceAll() method is just a convenience method that calls the regex replace methods.... And you can combine the two statements like so...
...
Note that although this works, you don't need to "double escape" them: the regex "\n" matches "\n". So, you could/should just do:
Henry Wong wrote:
Note that although this works, you don't need to "double escape" them: the regex "\n" matches "\n". So, you could/should just do:
I am not too sure if I completely agree with this. I agree that it will work. But in the first case, I am sending a "\n" string to the regex engine. And in the second case, I am sending an ASCII 10 character to the regex engine. It should work as the regex engine will replace the "\n" with the LF character anyway.
But I would feel more comfortable if I send readible text to the regex engine than control characters -- whether it works or not.
Henry
Anrd
"One of the best things you could do is to simplify a larger application into a smaller one by reducing its process and complexity - Fowler"
I'm full of tinier men! And a tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|