Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replace Function 1

Status
Not open for further replies.

Joules

MIS
Apr 25, 2001
28
US
I am trying to replace all occurances of double quotes (") in a string with single quotes ('). I have the following code that works for replacing words, but...
1. It only replaces the first occurance of the word.
2. I cannot figure out if I can change it to find and replace the quotes not a word.

Any suggestions?

The Function...

function ReplaceItem(patrn, replStr)
Dim regEx, str1
str1 = Request.Form("Reason") -->this is from my form
set regEx = New RegExp
regEx.Pattern = patrn
ReplaceItem = regEx.Replace(str1, replStr)
End Function

Here's how I call it...

<%Response.write( ReplaceItem(&quot;word2replace&quot;,&quot;withThis&quot;))%>
 
Perhaps try doing the following function:

Function ReplaceQuote(inStr)

Dim inStrLen, quotChar
inStrLen = Len(inStr)
quotChar = Chr(34)
Replace(inStr, quotChar, &quot;'&quot;, 1, inStrLen)

End Function

Syntax:
Replace(String, FindSTR, ReplaceSTR, Start, Count, Compare)
 
alistairpaul,

I get the following error when I tried your script...

Cannot use parentheses when calling a Sub

Replace(inStr,quotChar,&quot;'&quot;,1,inStrLen)
--------------------------------------^

Also, is the quotChar limiting the entry to 34 characters?

Thanks.
 
Error***
Replace(inStr, quotChar, &quot;'&quot;, 1, inStrLen)
has the Length and compare type reversed. You do not need either.
Also REPLACE is a function that returns a string. It does not modify the input string.
Use
ReplaceItem = Replace(str1, &quot;&quot;&quot;&quot;,&quot;'&quot;)
 
JohnYingling,

I was trying your suggestion as you replied...It worked!!!
Thank you for the tip.

Joules :-{}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top