[Javascript] RegExp

Rodney Myers rodney at aflyingstart.net
Wed Oct 10 18:32:25 CDT 2001


I found (in Win 98) that
    strNewStr = strString.replace(/\r/g,'')

worked as wished

I needed to modify a script I had for processing html and script into
displayable code for purposes of documentation

The old script did not touch the line ends. Just putting the outpust between
<pre></pre> tags was fine when editing the output in TextPad

Then I found in Dreamweaver (UltraDev 1 : must get the upgrade soon!) that in
wysiwig mode the cursor would not traverse the lines of PRE text to enable me
to apply styles and insert images.

So I thought if I made it one big para with a style defined as
font-face-"courier" then I would be better able to manipulate the appearance,
and for this I needed <br> tags on every line.

TextPad did a perfectly good replacement, but I thought if I modded my script I
could cut out a stage. I plan to add the top and tail HTML.

So I needed to replace every line end with <br> and the line end
Or insert a <br> before each line end.

Adapting your code, but worried about throwing it into an endless loop I went
for a two stage process

1. line end becomes <br> and a placeholder char sequence "!~!"
2. placeholder char sequence "!~!" is replaced with line end

// ADD <br> tags
    Buffer = Buffer.replace(/\r/g,'<br>!~!');
    Buffer = Buffer.replace(/!~!/g,'\r');


BTW the script works like this (I have several of the sort for various
purposes)
Input and output TEXTAREAs
Paste text into Input TEXTAREA
Process and display result in output TEXTAREA
Apply select() method to output TEXTAREA
Copy to clipboard the text thus highlighted
Paste to TextPad

The method is perfectly capable of handling script of several pages length.

Ben Curtis wrote:

> <script language="javascript">
> function replaceText()
>   {
>     var strString;
>     strString = myform.mytextarea.value;
>     strNewStr = strString.replace(/\n/g,'')
>     alert(strNewStr);
>     myform.mytextarea.value = strNewStr;
>   }
> </script>
>
> Untested, but ought to work.
>
> --
> +Ben Curtis
> ...established 1971.
>

--
Shop at ssistant Add-ons and Developer Workshops
http://www.aflyingstart.net/addons/

Enquiries regarding Shop at ssistant Classic training :
Call 01256 880770

Rodney Myers
Based in Oxford, England
Technical Director, Shop at ssistant eCommerce Solutions





More information about the Javascript mailing list