473,394 Members | 1,761 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Create string with values containing double quotes

Hi,

I'm looking to do some manipulation on a string containing html code
in asp which will involve me either using some regular expressions or
just plain old simple replace functionality. The text that I want to
use will have double quotes in it (as it's xhtml code) so I can't set
it as a string value and is actually brought into the page from a
content managed element (the details of which I don't think I'll need
to go into but needless to say it produces some valid xhtml)

What I want to be able to do is

<%
sTest = Replace("<a href="#">test link</a>", "<", "&lt;")
Response.Write (sTest)
%>

This will obviously give a syntax error because of the double quotes
surrounding the href attribute. The first parameter isn't built up
from other strings in the code before but is pulled directly from a
fixed content management system element which I can't format any other
way. So I can't do

<%
s1 = "<a href="#">test link</a>"
sTest = Replace(s1, "<", "&lt;")
Response.Write sTest
%>

I need the result of this replace to then be put into an xml attribute
so I need to convert the < and " characters to &lt; &gt; and &quot;
respectively.

Anyone have any ideas of how I could get this to work?

Many thanks

Aug 7 '07 #1
5 5094
Hels Bells wrote on 07 aug 2007 in microsoft.public.inetserver.asp.general:
I'm looking to do some manipulation on a string containing html code
in asp
[..]
<%
s1 = "<a href="#">test link</a>"
1 use single quotes in html:

s1 = "<a href='#'>test link</a>"

or
2 double the quotes in a vbscript string:

s1 = "<a href=""#"">test link</a>"

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Aug 7 '07 #2
Hels Bells wrote:
Hi,
This will obviously give a syntax error because of the double quotes
surrounding the href attribute.
In vbscript, special characters are "escaped" by doubling them

<%
sTest = Replace("<a href=""#"">test link</a>", "<", "&lt;")
Response.Write (sTest)
%>
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Aug 7 '07 #3
Hels Bells wrote:
Hi,

I'm looking to do some manipulation on a string containing html code
in asp which will involve me either using some regular expressions or
just plain old simple replace functionality. The text that I want to
use will have double quotes in it (as it's xhtml code) so I can't set
it as a string value and is actually brought into the page from a
content managed element (the details of which I don't think I'll need
to go into but needless to say it produces some valid xhtml)

What I want to be able to do is

<%
sTest = Replace("<a href="#">test link</a>", "<", "&lt;")
Response.Write (sTest)
%>
Oh, and use htmlencode instead of all those replace statements:

sTest = Server.htmlencode("<a href=""#"">test link</a>")

I won't comment on the use of "#" for the href

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Aug 7 '07 #4
On Aug 7, 5:23 pm, "Bob Barrows [MVP]" <reb01...@NOyahoo.SPAMcom>
wrote:
Hels Bells wrote:
Hi,
I'm looking to do some manipulation on a string containing html code
in asp which will involve me either using some regular expressions or
just plain old simple replace functionality. The text that I want to
use will have double quotes in it (as it's xhtml code) so I can't set
it as a string value and is actually brought into the page from a
content managed element (the details of which I don't think I'll need
to go into but needless to say it produces some valid xhtml)
What I want to be able to do is
<%
sTest = Replace("<a href="#">test link</a>", "<", "&lt;")
Response.Write (sTest)
%>

Oh, and use htmlencode instead of all those replace statements:

sTest = Server.htmlencode("<a href=""#"">test link</a>")

I won't comment on the use of "#" for the href

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
I can't double up the quotes (which I normally would) as the html
string is generated by a third party application that I can't alter
until it's in my asp page which is the main part of the problem. I
could use javascript to alter it but the manipulated string needs to
be available for all users in the html.

Aug 8 '07 #5


"delimiter" <he***********@gmail.comwrote in message
news:11**********************@22g2000hsm.googlegro ups.com...
On Aug 7, 5:23 pm, "Bob Barrows [MVP]" <reb01...@NOyahoo.SPAMcom>
wrote:
>Hels Bells wrote:
Hi,
I'm looking to do some manipulation on a string containing html code
in asp which will involve me either using some regular expressions or
just plain old simple replace functionality. The text that I want to
use will have double quotes in it (as it's xhtml code) so I can't set
it as a string value and is actually brought into the page from a
content managed element (the details of which I don't think I'll need
to go into but needless to say it produces some valid xhtml)
What I want to be able to do is
<%
sTest = Replace("<a href="#">test link</a>", "<", "&lt;")
Response.Write (sTest)
%>

Oh, and use htmlencode instead of all those replace statements:

sTest = Server.htmlencode("<a href=""#"">test link</a>")

I won't comment on the use of "#" for the href

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

I can't double up the quotes (which I normally would) as the html
string is generated by a third party application that I can't alter
until it's in my asp page which is the main part of the problem. I
could use javascript to alter it but the manipulated string needs to
be available for all users in the html.
So, the "third party application" passes you a string. Let's call that
string sString (for lack of a better name).

sString can contain absolutely any character - quotes, nulls, backspaces
(chr(8)), deletes (chr(127)), you name it.

VBScript doesn't care what that string contains - to it, it's just a string.

Now, you come along with...

sTest = Replace(sString, "<", "&lt;")

.... And the task will be performed - no matter how many quotes or other
"unusual" characters there are in the string.

As Bob Barrows explained though, if all you're doing is converting HTML
delimeters to literals, you're best off to use Server.HTMLencode() - it's
much faster and infinitely easier.

--
Bob Milutinovic
Cognicom - "Australia's Web Presence Specialists"
http://www.cognicom.net.au/
telephone (0417) 45-77-66
facsimile (02) 9824-2240
Aug 8 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Jeff | last post by:
Hi, does anyone know why this: <a onclick="insertatcaret(window.opener.document.formname.fieldname,'<td class="header">')">text</a> returns a "Unterminated String Constant" error message in IE...
7
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I...
5
by: Ann Marinas | last post by:
Happy New Year to all! :D I am currently developoing an application that imports data from a CSV file. Each comma represents an array item that I need to extract data with. My problem is...
9
by: Steven Blair | last post by:
Hi, I need to update a DB Table (MySQL 4.0) with a string representing a directory path (C:\Temp\In) but cannot get C# to do this. I take the string value from a textbox (myStr = myText.Text)...
12
by: Jeff S | last post by:
In a VB.NET code behind module, I build a string for a link that points to a JavaScript function. The two lines of code below show what is relevant. PopupLink = "javascript:PopUpWindow(" &...
1
by: Mark Rae | last post by:
Hi folks, Apologies - am having a bit of a "senior moment"... Is there a way to convert a string containing escaped characters into a verbatim string literal? I.e. converting something like...
6
by: karthi | last post by:
hi, I need user defined function that converts string to float in c. since the library function atof and strtod occupies large space in my processor memory I can't use it in my code. regards,...
15
by: Kapil Jain | last post by:
Dear All, What i need to achieve is : I am generating dynamic text boxes thru dhtml coding, i need onChange event of oragnistation text box i.e dynamically generated on click of "More" button in...
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.