Replies Back to Article

Replace VbCrLf in TextArea

really simple and good work...
November 9, 2001 by Burak AYDIN
I liked very mush this trick but I wonder, do I have the possibilty to not see <br> codes in my editing pages?
how to do the opposite?
February 12, 2002 by hans grimm

this is very handy! but, when the form is opened alle the text is in one block with <br>'s in between. that is to be expected, but it would be great if it was shown with all the line breaks again, so that a non-expert can re-format it in WYSIWYG...

how can i do this?

RE: how to do the opposite?
February 13, 2002 by hans grimm

hello, I'm replying to my own post because I've found it! see below:


this between <Head> </Head>:
-----------------------------------------------------------------------
<SCRIPT language="VBScript">
<!--
function RemoveHTML(strHTM)
    dim strTmp, strTmp1, i, lngLen, charOne, ynWait4End
    strTmp=""
    strtmp1="CStr"(strHTM)
    'MsgBox(cbool(ynDoFormat = 1))

        strTmp1 = Replace(CStr(strHTM),"<br>", vbCrLf)
        strTmp = Replace(strTmp1,"<tr>", vbCrLf)
        strTmp1 = Replace(strTmp,"</tr>", vbCrLf)
        strTmp = Replace(strTmp1,"<TR>", vbCrLf)
        strTmp1 = Replace(strTmp,"</TR>", vbCrLf)
        strTmp = Replace(strTmp1,"<Tr>", vbCrLf)
        strTmp1 = Replace(strTmp,"</Tr>", vbCrLf)
        strTmp = Replace(strTmp1,"<tR>", vbCrLf)
        strTmp1 = Replace(strTmp,"</tR>", vbCrLf)
        strTmp = Replace(strTmp1,"<TD>", "    ")
        strTmp1 = Replace(strTmp,"</TD>", "    ")
        strTmp = Replace(strTmp1,"<td>", "    ")
        strTmp1 = Replace(strTmp,"</td>", "    ")
        strTmp = Replace(strTmp1,"<Td>", "    ")
        strTmp1 = Replace(strTmp,"</Td>", "    ")
        strTmp = Replace(strTmp1,"<tD>", "    ")
        strTmp1 = Replace(strTmp,"</tD>", "    ")
        strTmp = Replace(strTmp1,"<P>", vbCrLf)
        strTmp1 = Replace(strTmp,"</P>", vbCrLf)
        strTmp = Replace(strTmp1,"<p>", vbCrLf)
        strTmp1 = Replace(strTmp,"</p>", vbCrLf)
        strTmp = Replace(strTmp1,"<Br>", vbCrLf)
        strTmp1 = Replace(strTmp,"</Br>", vbCrLf)
        strTmp = Replace(strTmp1,"<bR>", vbCrLf)
        strTmp1 = Replace(strTmp,"</bR>", vbCrLf)
        strTmp = Replace(strTmp1,"<BR>", vbCrLf)
        strTmp1 = Replace(strTmp,"</BR>", vbCrLf)
        strTmp=""
   
 ynWait4End = False
    lngLen = Len(strTmp1)
    For i = 1 To lngLen
        charone="Mid"(strTmp1,i,1)
        If charOne="<" Then
            ynWait4End = True
            charOne=""
        End If
        If ynWait4End = True Then
            If charOne = ">" Then
                ynWait4End = False
            End If
            charOne = ""
        End If
        strTmp = strTmp & charOne
    next
    RemoveHTML= strTmp
    'spnDump.innerHTML=strTmp
End function


//-->
</SCRIPT>
------------------------------------------------------------------------
this in the form-element tag:

onFocus="NaamTextarea.value=RemoveHTML(NaamTextarea.value)"

and you are homefree

this way the textarea will display the text correctly onFocus.

have fun

RE: RE: how to do the opposite?
February 13, 2002 by hans grimm
note: 'naam.TextArea' is to be replaced by the name of your textarea...
RE: RE: RE: how to do the opposite?
March 4, 2002 by hans grimm

one other little thing I found out: if you do not want all tags to be stripped (such as <b> or <a>, etc.), in the script, replace 'If charOne="<" Then' by 'If charOne="" Then', and 'If charOne = ">" Then' by 'If charOne = "" Then'.

this little quirk was brought to my attention by a client who had just been entering some e-mail links in the field, and they were stripped out...

Great little tutorial
December 17, 2002 by Ralf Fredriksson
I´ve searched this place for this functon and couldn´t find it so I wrote in the MX forum and asked for this. No answers. But I found this tutorial by accident and it worked great. Thanks
RE: RE: how to do the opposite?
March 17, 2003 by Tim Bednar

This little trick works great for Win IE, but does not work on my Mac IE? Any suggestions?

RE: RE: RE: how to do the opposite?
March 17, 2003 by Tim Bednar

I figured it out. The VBScript does not work on the MAC because it is client side. So I use this instead...

<%
Dim strBody
strBody = rsEntry.Fields.Item("Body")
%>
<textarea name="txtBody"><%=Replace strBody,"<br>",VbCrLf)%></textarea>

RE: RE: RE: RE: how to do the opposite?
June 27, 2003 by hans grimm

Yes! I have discovered the way to do it all serverside and show the formfield with the text already formatted:

step 1:

put the script above the <html>-tags, like this:

<%
function RemoveHTML(strHTM)
    dim strTmp, strTmp1, i, lngLen, charOne, ynWait4End
    strTmp=""
    strtmp1="CStr"(strHTM)
    'MsgBox(cbool(ynDoFormat = 1))

        strTmp1 = Replace(CStr(strHTM),"<br>", vbCrLf)
        strTmp = Replace(strTmp1,"<tr>", vbCrLf)
        strTmp1 = Replace(strTmp,"</tr>", vbCrLf)
        strTmp = Replace(strTmp1,"<TR>", vbCrLf)
        strTmp1 = Replace(strTmp,"</TR>", vbCrLf)
        strTmp = Replace(strTmp1,"<Tr>", vbCrLf)
        strTmp1 = Replace(strTmp,"</Tr>", vbCrLf)
        strTmp = Replace(strTmp1,"<tR>", vbCrLf)
        strTmp1 = Replace(strTmp,"</tR>", vbCrLf)
        strTmp = Replace(strTmp1,"<TD>", "    ")
        strTmp1 = Replace(strTmp,"</TD>", "    ")
        strTmp = Replace(strTmp1,"<td>", "    ")
        strTmp1 = Replace(strTmp,"</td>", "    ")
        strTmp = Replace(strTmp1,"<Td>", "    ")
        strTmp1 = Replace(strTmp,"</Td>", "    ")
        strTmp = Replace(strTmp1,"<tD>", "    ")
        strTmp1 = Replace(strTmp,"</tD>", "    ")
        strTmp = Replace(strTmp1,"<P>", vbCrLf)
        strTmp1 = Replace(strTmp,"</P>", vbCrLf)
        strTmp = Replace(strTmp1,"<p>", vbCrLf)
        strTmp1 = Replace(strTmp,"</p>", vbCrLf)
        strTmp = Replace(strTmp1,"<Br>", vbCrLf)
        strTmp1 = Replace(strTmp,"</Br>", vbCrLf)
        strTmp = Replace(strTmp1,"<bR>", vbCrLf)
        strTmp1 = Replace(strTmp,"</bR>", vbCrLf)
        strTmp = Replace(strTmp1,"<BR>", vbCrLf)
        strTmp1 = Replace(strTmp,"</BR>", vbCrLf)
        strTmp=""
   
 ynWait4End = False
    lngLen = Len(strTmp1)
    For i = 1 To lngLen
        charone="Mid"(strTmp1,i,1)
        If charOne="" Then
            ynWait4End = True
            charOne=""
        End If
        If ynWait4End = True Then
            If charOne = "" Then
                ynWait4End = False
            End If
            charOne = ""
        End If
        strTmp = strTmp & charOne
    next
    RemoveHTML= strTmp
    'spnDump.innerHTML=strTmp
End function
%>

then, you only have to put this in the formfield:

<%=RemoveHTML(Recordset1.Fields.Item("text").Value)%>

and voila..

RE: RE: how to do the opposite?
February 7, 2005 by steve powell

Remember that the Replace function has more arguments that will greatly simplify your code by allowing case INSensiTive searching

strTmp1 = Replace(CStr(strHTM),"<br>", vbCrLf, 1,-1, 1)
strTmp = Replace(strTmp1,"<tr>", vbCrLf, 1,-1, 1)
strTmp1 = Replace(strTmp,"</tr>", vbCrLf, 1,-1, 1)
strTmp = Replace(strTmp1,"<td>", vbCrLf, 1,-1, 1)
strTmp1 = Replace(strTmp,"</td>", vbCrLf, 1,-1, 1)
strTmp1 = Replace(strTmp,"<p>", vbCrLf, 1,-1, 1)
strTmp1 = Replace(strTmp,"</p>", vbCrLf, 1,-1, 1)
etc. . .

I'm sure someone could come up with a wildcard function to even further simplify this (something that looks for <?p> or <?t?> or <?br>) but you get the idea.  Also remember that xhtml is all lowercase.

See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vsfctReplace.asp

-S