When is a newline not a newline?
When is a newline not a newline?
- Subject: When is a newline not a newline?
- From: email@hidden
- Date: Thu, 09 Oct 2003 14:56:20 CDT
- Priority: 3 (Normal)
[demime could not interpret encoding binary - treating as plain text]
I have some code that is supposed to take newlines out of a string. It is
supposed to replace an actual newline (Java "\n", right?) with the
escaped newline (Java string literal "\\n" to get an actual '\n' in the
string, not a newline). This is for use with javascript, if you're wondering.
It at first looks like it works. There is a literal '/' 'n' in the
produced String every place there was a newline. Looking at the string
in my debugger, the source string prints out with actual line breaks, the
produced string does not. But... when the string is output into the
content of my page, it mysteriously has newlines in it, NEXT to every
literal '\' 'n' in the string. And even though the produce string doesn't
look like it has any newlines in the debugger, if I cut-and-paste the
output string into another document, say a PB text window... it has
newlines in it.
What the heck is going on? I'm guessing that it's got to do with
OS-variant newlines. Maybe I've got the old '\r' charecter hiding in
there? But if Java "\n" doesn't match it... how am I supposed to find
it? It's messing up the javascript code, which DOES see it as a newline,
interrupting a JS string literal before the closing quote, which is not
allowed. If I'm right, and it is this weird "\r" char... how the heck do
I find it? There doesn't seem to be any Java "\r" special code.
Basically, what's the way to find newlines in a String, regardless of
what OS the String was produced by, and eliminate them (or replace them
with something else, either way). Any ideas?
--Jonathan
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.