javascript to replace inverted commas
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Plusnet Community
- :
- Forum
- :
- Other forums
- :
- Tech Help - Software/Hardware etc
- :
- javascript to replace inverted commas
javascript to replace inverted commas
24-01-2017 12:28 PM - edited 24-01-2017 12:56 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
i have a little script that strips out any characters from a text variable.
Function Encode(DirtyText) Dim CleanText Cleantext = Server.HtmlEncode(DirtyText) CleanText = Replace(CleanText, "'", "''") CleanText = Replace(CleanText, vbCrLf, "<br>") Encode = CleanText End Function
i want it to be able to strip out inverted commas too, ", and replace it with something else>
however
CleanText = Replace(CleanText, """, ".")
doesn't work as it doesn't like """.
so does anyone know how to do this?
the end result is used as follows.
newvariable = Encode(cstr(request.form("oldvariable")))
Re: javascript to replace inverted commas
24-01-2017 1:03 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Try
CleanText = Replace(CleanText, '"', ".")
or
CleanText = Replace(CleanText, "\"", ".")
jelv (a.k.a Spoon Whittler) Why I have left Plusnet (warning: long post!) Broadband: Andrews & Arnold Home::1 (FTTC 80/20) Line rental: Pulse 8 Home Line Rental (£14.40/month) Mobile: iD mobile (£4/month) |
Re: javascript to replace inverted commas
24-01-2017 1:07 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator

Re: javascript to replace inverted commas
24-01-2017 1:14 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Try this :
cleanText = dirtyText.replace(/['"]+/g, '.')
Re: javascript to replace inverted commas
24-01-2017 1:19 PM - edited 24-01-2017 1:19 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
nope
Microsoft VBScript compilation error '800a03ea' Syntax error /includes/functions.asp, line 44 cleanText = dirtyText.replace(/['"]+/g, '.') ------------------------------^
Re: javascript to replace inverted commas
24-01-2017 1:34 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Try using
Chr(34)
as the string to be replaced

Re: javascript to replace inverted commas
24-01-2017 1:43 PM - edited 24-01-2017 1:44 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
VBScript so it may need escaping so put a \ in front of the forward slashes. i.e.
(\/['"]+\/g, '.')
Edit:- Just so you know (assuming this works) this will replace all occurrences of a double quote with a .
Re: javascript to replace inverted commas
24-01-2017 2:03 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
still nope
Microsoft VBScript compilation error '800a03ea' Syntax error /staffportal/includes/functions.asp, line 44 cleanText = dirtyText.replace(\/['"]+\/g, '.') ------------------------------^

Re: javascript to replace inverted commas
24-01-2017 2:11 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Re: javascript to replace inverted commas
25-01-2017 6:11 PM - edited 25-01-2017 6:15 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
@chenks76 wrote:
[...]
CleanText = Replace(CleanText, """, ".")doesn't work as it doesn't like """.
so does anyone know how to do this?
The double-quote " is a special character in VBScript and so to use it literally (i.e. without special meaning; just as a character) use two consecutive double-quotes instead. Thus:
CleanText = Replace(CleanText, """", ".")
(Caveat: I don't know this from first hand experience of VBScript, just a cursory Internet search)
Re: javascript to replace inverted commas
26-01-2017 10:27 AM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
It would have helped if your original post had said you were trying to use VBscript and not Javascript!
jelv (a.k.a Spoon Whittler) Why I have left Plusnet (warning: long post!) Broadband: Andrews & Arnold Home::1 (FTTC 80/20) Line rental: Pulse 8 Home Line Rental (£14.40/month) Mobile: iD mobile (£4/month) |
Re: javascript to replace inverted commas
29-01-2017 7:38 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Did you get anywhere with this @chenks76?
Re: javascript to replace inverted commas
30-01-2017 9:38 AM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
tied up with other stuff right now.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Plusnet Community
- :
- Forum
- :
- Other forums
- :
- Tech Help - Software/Hardware etc
- :
- javascript to replace inverted commas