Create string with values containing double quotes
Create string with values containing double quotes
am 07.08.2007 18:09:00 von Hels Bells
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("", "<", "<")
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 = ""
sTest = Replace(s1, "<", "<")
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 < > and "
respectively.
Anyone have any ideas of how I could get this to work?
Many thanks
Re: Create string with values containing double quotes
am 07.08.2007 18:21:41 von reb01501
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("", "<", "<")
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.
Re: Create string with values containing double quotes
am 07.08.2007 18:22:45 von exjxw.hannivoort
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 = ""
1 use single quotes in html:
s1 = ""
or
2 double the quotes in a vbscript string:
s1 = ""
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Re: Create string with values containing double quotes
am 07.08.2007 18:23:31 von reb01501
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("", "<", "<")
> Response.Write (sTest)
> %>
Oh, and use htmlencode instead of all those replace statements:
sTest = Server.htmlencode("")
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.
Re: Create string with values containing double quotes
am 08.08.2007 10:59:08 von Hels Bells
On Aug 7, 5:23 pm, "Bob Barrows [MVP]"
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("", "<", "<")
> > Response.Write (sTest)
> > %>
>
> Oh, and use htmlencode instead of all those replace statements:
>
> sTest = Server.htmlencode("")
>
> 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.
Re: Create string with values containing double quotes
am 08.08.2007 17:51:21 von Bob Milutinovic
"delimiter" wrote in message
news:1186563548.121836.221920@22g2000hsm.googlegroups.com...
> On Aug 7, 5:23 pm, "Bob Barrows [MVP]"
> 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("", "<", "<")
>> > Response.Write (sTest)
>> > %>
>>
>> Oh, and use htmlencode instead of all those replace statements:
>>
>> sTest = Server.htmlencode("")
>>
>> 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, "<", "<")
.... 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