473,657 Members | 2,594 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5140
Hels Bells wrote on 07 aug 2007 in microsoft.publi c.inetserver.as p.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.htmlenco de("<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...@NOyah oo.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.htmlenco de("<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.goog legroups.com...
On Aug 7, 5:23 pm, "Bob Barrows [MVP]" <reb01...@NOyah oo.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.htmlenco de("<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.HTMLenco de() - 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
13479
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 6.0 but if I take out the double quotes around header it does not? I need double quotes around header, I thought this was possible in javascript so long as the pair of double quotes is surrounded by a pair of single quotes.
7
8850
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 want my users to be able to select a report, click on a command button on a form, which will then automatically create the report as a pdf file and save it to the user's machine. I am using Adobe Acrobat (5.0 I think) and have Adobe Distiller as a
5
3235
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 this... I am encountering a string that has the example below: a, b, c. "d,e,f,g", abcdef
9
2338
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) and pass this to a function. The function builds up a SQL string which will be executed:
12
9630
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(" & Chr(34) & PopUpWindowTitle & Chr(34) & ", " & Chr(34) & CurrentEventDetails & ")" strTemp += "<BR><A HREF='#' onClick='" & PopupLink & "'>" & EventName & "</A><BR>" The problem I have is that when the string variables or contain a string with an...
1
5812
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 "This string contains \"double quotes\" and \'single quotes\'"
6
7606
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, Karthi
15
2312
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 myhtml page in series manner like oragnisation0,oragnisation1,oragnisation2 and so on, and popup window will open onChange event of (oraganisation<iCount>) with one query string / parameter i.e value of oraganisation so that i will use that...
4
12427
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 this: can Access create the document and place it as an OLE object to the relevant table? Any help is greatly appreciated. Ricky
0
8392
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8305
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8730
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4151
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1950
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1607
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.