[Project_owners] Editor content

Thomas Schmid schmid-thomas at gmx.net
Mon Sep 11 06:18:03 EDT 2006


Hi,

Michael Buckley wrote:
> Thanks that is what I needed, though it put out \n\r were it should only
> be \n  if you understand what I mean.  Easy enough to fix.  Here is what
> my script looks like.
>
>
>   var editor = document.getElementById('myEditor');
>
>  var oldStr =
> editor.getEditor(editor.contentWindow).outputToString("text/plain", 0);
>    var findStr = '\n\r';
>    var repStr = '';
>
>    var srchNdx = 0;
>    var newStr = '';
>    while (oldStr.indexOf(findStr,srchNdx) != -1) {
>        newStr  = 
> oldStr.substring(srchNdx,oldStr.indexOf(findStr,srchNdx));
>        newStr  = repStr;
>        srchNdx = (oldStr.indexOf(findStr,srchNdx)   findStr.length   1);
>    }
>    newStr  = oldStr.substring(srchNdx,oldStr.length);
>
> newStr being the text.

you can also use regex to convert \n\r into a \n:
 
  // convert all \n\r to \n...
  var newStr = oldStr.replace(/\n\r/g,"\n");

Are you really sure, that you got a \n\r and not \r\n ?
A \n\r would be very strange, while \r\n is normal on Windows.
Old Macs use \r. Unix, Linux, Mac OS X and Mozilla define a newline as \n.

Regards

Thomas



More information about the Project_owners mailing list