replacing quote marks

  • Thread starter Rcarman11 via AccessMonster.com
  • Start date
R

Rcarman11 via AccessMonster.com

I need to replace strings that have " marks in them and It keeps giving me an
error. I need to delete html tags like
<a href="testing home page.html">
so i've been using a replace function that looks something like this
Data3: Replace([data2],"<a href*","")
It doesn't do anything because it runs into the quote mark and ends. I tried
puting a quote mark with in quote marks like this

Data3: Replace([data2]," " ","inch")
so i can then use the above replace function.
Any ideas?
 
J

John Spencer

Try

Replace([data2],"<a href*" & Chr(34),"")

Or perhaps doubling up the quotes to get one quote.


Replace([data2],"<a href*""","")

'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================
 
R

Rcarman11 via AccessMonster.com

john, That still didn't work. i don't think its the quotes anymore. I've been
playing around with it, and even when i take out the quotes I still can't
replace the html tags. any other ideas?

John said:
Try

Replace([data2],"<a href*" & Chr(34),"")

Or perhaps doubling up the quotes to get one quote.

Replace([data2],"<a href*""","")

'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================
I need to replace strings that have " marks in them and It keeps giving me an
error. I need to delete html tags like
[quoted text clipped - 7 lines]
so i can then use the above replace function.
Any ideas?
 
J

John Spencer

What version of Access are you using?

What error are you getting?

If you are using Access 2000 without the latest service packs, then I
believe that Access SQL expression service doesn't recognize the replace
function.

Are you sure there is something in Data2?



'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================

john, That still didn't work. i don't think its the quotes anymore. I've been
playing around with it, and even when i take out the quotes I still can't
replace the html tags. any other ideas?

John said:
Try

Replace([data2],"<a href*" & Chr(34),"")

Or perhaps doubling up the quotes to get one quote.

Replace([data2],"<a href*""","")

'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================
I need to replace strings that have " marks in them and It keeps giving me an
error. I need to delete html tags like
[quoted text clipped - 7 lines]
so i can then use the above replace function.
Any ideas?
 
R

Rcarman11 via AccessMonster.com

I am using Access 2002. I've used the replace function alot. It's just being
weird when it comes to anything in <. like
<a href=" test?hompage.html> or <DIV align="center">

for example I use
Data1: Replace([Data],"</b>","<f""Heavy"">")
Data4: Replace([Data3],"</font>","<$c>")
to replace html tags with quark tags. each time I run a replace i call it
Data"n" and then the next replace function used Data"n" and is called
Data"n+1". This way I can use one quary and replace all the html tags with
tags we can use. I'm not getting an error It's just not replacing <a
href="test?homepage.html> with nothing.

Data2:Replace([Data1],"<a href*>," ")

John said:
What version of Access are you using?

What error are you getting?

If you are using Access 2000 without the latest service packs, then I
believe that Access SQL expression service doesn't recognize the replace
function.

Are you sure there is something in Data2?

'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================
john, That still didn't work. i don't think its the quotes anymore. I've been
playing around with it, and even when i take out the quotes I still can't
[quoted text clipped - 20 lines]
 
J

John Spencer

Could you post the entire query? I think you may be doing something other
than what I expect.

Beyond that I am stuck on why it is not working.



--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..

Rcarman11 via AccessMonster.com said:
I am using Access 2002. I've used the replace function alot. It's just
being
weird when it comes to anything in <. like
<a href=" test?hompage.html> or <DIV align="center">

for example I use
Data1: Replace([Data],"</b>","<f""Heavy"">")
Data4: Replace([Data3],"</font>","<$c>")
to replace html tags with quark tags. each time I run a replace i call it
Data"n" and then the next replace function used Data"n" and is called
Data"n+1". This way I can use one quary and replace all the html tags with
tags we can use. I'm not getting an error It's just not replacing <a
href="test?homepage.html> with nothing.

Data2:Replace([Data1],"<a href*>," ")

John said:
What version of Access are you using?

What error are you getting?

If you are using Access 2000 without the latest service packs, then I
believe that Access SQL expression service doesn't recognize the replace
function.

Are you sure there is something in Data2?

'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================
john, That still didn't work. i don't think its the quotes anymore. I've
been
playing around with it, and even when i take out the quotes I still
can't
[quoted text clipped - 20 lines]
so i can then use the above replace function.
Any ideas?
 
R

Rcarman11 via AccessMonster.com

Here it is. The second Replace function for replaceing the </a> works just
fine.

SELECT [test data].subgrpID, [test data].copy AS copy2, Replace([copy2],"<a
href=*>"," ") AS Data2, Replace([data2],"</a>","") AS Data3
FROM [test data];


John said:
Could you post the entire query? I think you may be doing something other
than what I expect.

Beyond that I am stuck on why it is not working.
I am using Access 2002. I've used the replace function alot. It's just
being
[quoted text clipped - 36 lines]
 
J

John Spencer

SELECT [test data].subgrpID
, [test data].copy AS copy2
, Replace([copy2],"<ahref=*>"," ") AS Data2
, Replace([data2],"</a>","") AS Data3
FROM [test data];

From the looks of that I can only guess that "<ahref=*>" does not exist in
the field Copy. I would check for spaces or other characters being present
between the <> characters.

Also try the full set of arguments

Replace([copy2],"<ahref=*>"," ",1,-1,1) AS Data2

Which says start at position 1, replace all matches, compare as text (ignore
case).


--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..

Rcarman11 via AccessMonster.com said:
Here it is. The second Replace function for replaceing the </a> works just
fine.

SELECT [test data].subgrpID, [test data].copy AS copy2,
Replace([copy2],"<a
href=*>"," ") AS Data2, Replace([data2],"</a>","") AS Data3
FROM [test data];


John said:
Could you post the entire query? I think you may be doing something other
than what I expect.

Beyond that I am stuck on why it is not working.
I am using Access 2002. I've used the replace function alot. It's just
being
[quoted text clipped - 36 lines]
so i can then use the above replace function.
Any ideas?
 
R

Rcarman11 via AccessMonster.com

John, just a side note. I read that you can't use wildcards in a replace
function. So I guess I'm not going to be able to use a replace query to get
rid of html tags. I just want to thank you anyways for the help.

John said:
SELECT [test data].subgrpID
, [test data].copy AS copy2
, Replace([copy2],"<ahref=*>"," ") AS Data2
, Replace([data2],"</a>","") AS Data3
FROM [test data];

From the looks of that I can only guess that "<ahref=*>" does not exist in
the field Copy. I would check for spaces or other characters being present
between the <> characters.

Also try the full set of arguments

Replace([copy2],"<ahref=*>"," ",1,-1,1) AS Data2

Which says start at position 1, replace all matches, compare as text (ignore
case).
Here it is. The second Replace function for replaceing the </a> works just
fine.
[quoted text clipped - 14 lines]
 
J

John Spencer

Strange, I've never heard that.

I just tested this in VBA window and had no problems at all replacing
wildcards.

?Replace("<*>","*","XXXX") returned <XXXX>

'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================

John, just a side note. I read that you can't use wildcards in a replace
function. So I guess I'm not going to be able to use a replace query to get
rid of html tags. I just want to thank you anyways for the help.

John said:
SELECT [test data].subgrpID
, [test data].copy AS copy2
, Replace([copy2],"<ahref=*>"," ") AS Data2
, Replace([data2],"</a>","") AS Data3
FROM [test data];
From the looks of that I can only guess that "<ahref=*>" does not exist in
the field Copy. I would check for spaces or other characters being present
between the <> characters.

Also try the full set of arguments

Replace([copy2],"<ahref=*>"," ",1,-1,1) AS Data2

Which says start at position 1, replace all matches, compare as text (ignore
case).
Here it is. The second Replace function for replaceing the </a> works just
fine.
[quoted text clipped - 14 lines]
so i can then use the above replace function.
Any ideas?
 
J

John W. Vinson

Strange, I've never heard that.

I just tested this in VBA window and had no problems at all replacing
wildcards.

?Replace("<*>","*","XXXX") returned <XXXX>

John, that will replace a literal asterisk. What I gather RCarmen wants is to
replace <(any arbitrary HTML tag contents)> with nothing - treating * as a
wildcard for any arbitrary text string of any length.

I started to fiddle with a custom VBA code to do so, but I don't know how to
deal with > and < characters which are not part of an HTML tag.

I suspect that there are standard routines in the web programming world which
do this... but haven't taken the time to go look for one.

John W. Vinson [MVP]
 
J

John Spencer

AHHHH!! The sun comes up, the light dawns, understanding is granted the
student.

--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 
R

Rcarman11 via AccessMonster.com

Vinson is right. I don't need to replace the literal * mark. I can get rid of
the < and > marks with a simple replace function. The problem lies with the
unknown text after the <a href=. Vinson if you get anywhere with your VBA
code I would love to hear it. Right now I'm trying to write a macro. A
simple find and replace works but I need to automate the whole process. So
I'm hoping I can use a macro to open a find and replace and run it
automatically.

John said:
AHHHH!! The sun comes up, the light dawns, understanding is granted the
student.
[quoted text clipped - 17 lines]
John W. Vinson [MVP]
 
J

John W. Vinson

Vinson is right. I don't need to replace the literal * mark. I can get rid of
the < and > marks with a simple replace function. The problem lies with the
unknown text after the <a href=. Vinson if you get anywhere with your VBA
code I would love to hear it. Right now I'm trying to write a macro. A
simple find and replace works but I need to automate the whole process. So
I'm hoping I can use a macro to open a find and replace and run it
automatically.

Well, IF you can be confidant that it's safe to assume a) that for every < in
the text field there is a following >; and b) that it's safe to delete those
characters and everything between them, then this function should do the job.
It does NOT have error checking (if there is a < without a > it will delete
from the < to the end of the field) and could certainly be improved:

Public Function ZapTags(strIn As String)
Dim strOut As String
Dim iLeft As Integer, iRight As Integer
iLeft = InStr(strIn, "<") ' find first <
Do While iLeft > 0
strOut = strOut & Left(strIn, iLeft - 1) ' output text to left of <
iRight = InStr(strIn, ">")
strIn = Mid(strIn, iRight + 1) ' discard text between < >
iLeft = InStr(strIn, "<") ' find next < if any
Loop
strOut = strOut & strIn ' append rest of string after last >
ZapTags = strOut
End Function


To use, just run an Update query updateing your text field Fieldname to

ZapTags([fieldname])

John W. Vinson [MVP]
 
J

John W. Vinson

Vinson is right. I don't need to replace the literal * mark. I can get rid of
the < and > marks with a simple replace function. The problem lies with the
unknown text after the <a href=. Vinson if you get anywhere with your VBA
code I would love to hear it. Right now I'm trying to write a macro. A
simple find and replace works but I need to automate the whole process. So
I'm hoping I can use a macro to open a find and replace and run it
automatically.

OOPS!!!

Left out one important line: as written a missing > will throw it into an
infinite loop. Change to:

Public Function ZapTags(strIn As String)
Dim strOut As String
Dim iLeft As Integer, iRight As Integer
iLeft = InStr(strIn, "<") ' find first <
Do While iLeft > 0
strOut = strOut & Left(strIn, iLeft - 1) ' output text to left of <
iRight = InStr(strIn, ">")
If iRight = 0 Then iRight = Len(strIn)
strIn = Mid(strIn, iRight + 1) ' discard text between < >
iLeft = InStr(strIn, "<") ' find next < if any
Loop
strOut = strOut & strIn
ZapTags = strOut
End Function


John W. Vinson [MVP]
 
R

Rcarman11 via AccessMonster.com

Thank you John, I have to move on to something new but I will get back to
your code and try it out.
Vinson is right. I don't need to replace the literal * mark. I can get rid of
the < and > marks with a simple replace function. The problem lies with the
[quoted text clipped - 3 lines]
I'm hoping I can use a macro to open a find and replace and run it
automatically.

OOPS!!!

Left out one important line: as written a missing > will throw it into an
infinite loop. Change to:

Public Function ZapTags(strIn As String)
Dim strOut As String
Dim iLeft As Integer, iRight As Integer
iLeft = InStr(strIn, "<") ' find first <
Do While iLeft > 0
strOut = strOut & Left(strIn, iLeft - 1) ' output text to left of <
iRight = InStr(strIn, ">")
If iRight = 0 Then iRight = Len(strIn)
strIn = Mid(strIn, iRight + 1) ' discard text between < >
iLeft = InStr(strIn, "<") ' find next < if any
Loop
strOut = strOut & strIn
ZapTags = strOut
End Function

John W. Vinson [MVP]
 
Top