Click to See Complete Forum and Search --> : Newline Character not translating to Notepad
plucky
03-31-2003, 01:16 PM
I have a script that allows a user to click on a link to have a string placed in their clipboard. In this string, i want to use the newline character (\n) for formatting (this is to format an address).
So i hit the link to copy the string, and then i paste it into Notepad. In notepad, it is all on one line and instead of having a newline, it has a box character...
How do i generate a newline that will translate into notepad?
My code looks like this:
var strClipBoard = strAddress + "\n" + strCity;
let me know if you need all of the code...to test this with.
thanks
gil davis
03-31-2003, 01:43 PM
Since NotePad is a text editor, I would think that embedding the carriage return (%D) and line feed (%A) should do what you want.
plucky
03-31-2003, 02:33 PM
Where do you get and how do you embed the "%D" and "%A" characters into javascript? I can't find any documentation on these constants. All i can find is "\n" and "\r" for javascript.
THanks
jeffmott
03-31-2003, 03:31 PM
Any of the following ways."\r\n"
"\x0d\x0a"
"\u000d\u000a"
plucky
03-31-2003, 04:09 PM
All of these work for display within the html document... but after they have been placed on the clipboard and pasted into notepad, i get this output:
nameaddresscity state zip
instead of:
name
address
city state zip
I am using the createTextRange method to copy the contents of an <input> to the clipboard. Maybe this process is screwing with the values? It pastes into Word ok...but when you put the document in outline mode...you can see that there are not carriage returns (or maybe line feeds is correct term) for each line.
jeffmott
03-31-2003, 06:29 PM
There may actually be no way to solve this then. Many programming libraries all work together to let the programmer treat a single character (\n) as the line terminator, irrespective of the external representation (Mac, *nix, Win all have different line terminators). When you copy the string into the clipboard it is changing the external representation (CRLF) to the internal representation (\n). And since pasting from the clipboard doesn't actually write to the disk it is never converted back to the system's external representation. As you have noticed other programs such as Word will recognize all the different variations of line terminators, but notepad does not. Something you may have to look for (I'm a little lazy to check myself right now :) is if JavaScript will allow you to declare the string you pass as binary data rather than textual. This will stop it from converting the line terminator. Also be aware though that forcing the Windows line terminator will do Mac and *nix users no good.
plucky
03-31-2003, 06:39 PM
Thanks for the info, i'll look into a binary string. This is for a specialized app so...Macntrash, *nix, or even netscape don't pull me down on this one.