Connecting Tech Pros Worldwide Forums | Help | Site Map

function that removes the punctuation and some characters like (*&^%$#@!<>?"} from a text string

Beznas
Guest
 
Posts: n/a
#1: Jul 19 '05
Hi All;

I'm trying to create an ASP function called CleanX that removes the
punctuation and some characters like (*&^%$#@!<>?"}|{..) from a text
string

I came up with this but It doesn't look like it's working.

Can anyone help please.
THANK YOU.


Function CleanX(strString)

yTemp = strString
yTemp = replace(yTemp,"*","")
yTemp = replace(yTemp,"!","")
yTemp = replace(yTemp,"""","")
yTemp = replace(yTemp,"£","")
yTemp = replace(yTemp,"$","")
yTemp = replace(yTemp,"%","")
yTemp = replace(yTemp,"^","")
yTemp = replace(yTemp,"&","")
yTemp = replace(yTemp,"(","")
yTemp = replace(yTemp,")","")
yTemp = replace(yTemp,"_","")
yTemp = replace(yTemp,"-","")
yTemp = replace(yTemp,"=","")
yTemp = replace(yTemp,"+","")
yTemp = replace(yTemp,"#","")
yTemp = replace(yTemp,"~","")
yTemp = replace(yTemp,"[","")
yTemp = replace(yTemp,"{","")
yTemp = replace(yTemp,"]","")
yTemp = replace(yTemp,"}","")
yTemp = replace(yTemp,";","")
yTemp = replace(yTemp,":","")
yTemp = replace(yTemp,"@","")
yTemp = replace(yTemp,"'","-")
yTemp = replace(yTemp,"<","")
yTemp = replace(yTemp,",","")
yTemp = replace(yTemp,">","")
yTemp = replace(yTemp,".","")
yTemp = replace(yTemp,"?","")
yTemp = replace(yTemp,"/","")
yTemp = replace(yTemp,"\","")
yTemp = replace(yTemp,"|","")
yTemp = replace(yTemp,"¬","")
yTemp = replace(yTemp,"`","")
yTemp = replace(yTemp,"é","e")
yTemp = replace(yTemp,"è","e")
yTemp = replace(yTemp,"à","a")
yTemp = replace(yTemp,"ï","i")
yTemp = replace(yTemp,"ê","e")
yTemp = replace(yTemp,"â","a")
yTemp = replace(yTemp,"ô","o")
strString = yTemp
End Function





Tom B
Guest
 
Posts: n/a
#2: Jul 19 '05

re: function that removes the punctuation and some characters like (*&^%$#@!<>?"} from a text string


Your last line should be CleanX=yTemp
You may want to look into Regular Expressions, as it may be easier and
faster.

"Beznas" <walou@walou.com> wrote in message
news:%23weMnxydDHA.1772@TK2MSFTNGP10.phx.gbl...[color=blue]
> Hi All;
>
> I'm trying to create an ASP function called CleanX that removes the
> punctuation and some characters like (*&^%$#@!<>?"}|{..) from a[/color]
text[color=blue]
> string
>
> I came up with this but It doesn't look like it's working.
>
> Can anyone help please.
> THANK YOU.
>
>
> Function CleanX(strString)
>
> yTemp = strString
> yTemp = replace(yTemp,"*","")
> yTemp = replace(yTemp,"!","")
> yTemp = replace(yTemp,"""","")
> yTemp = replace(yTemp,"£","")
> yTemp = replace(yTemp,"$","")
> yTemp = replace(yTemp,"%","")
> yTemp = replace(yTemp,"^","")
> yTemp = replace(yTemp,"&","")
> yTemp = replace(yTemp,"(","")
> yTemp = replace(yTemp,")","")
> yTemp = replace(yTemp,"_","")
> yTemp = replace(yTemp,"-","")
> yTemp = replace(yTemp,"=","")
> yTemp = replace(yTemp,"+","")
> yTemp = replace(yTemp,"#","")
> yTemp = replace(yTemp,"~","")
> yTemp = replace(yTemp,"[","")
> yTemp = replace(yTemp,"{","")
> yTemp = replace(yTemp,"]","")
> yTemp = replace(yTemp,"}","")
> yTemp = replace(yTemp,";","")
> yTemp = replace(yTemp,":","")
> yTemp = replace(yTemp,"@","")
> yTemp = replace(yTemp,"'","-")
> yTemp = replace(yTemp,"<","")
> yTemp = replace(yTemp,",","")
> yTemp = replace(yTemp,">","")
> yTemp = replace(yTemp,".","")
> yTemp = replace(yTemp,"?","")
> yTemp = replace(yTemp,"/","")
> yTemp = replace(yTemp,"\","")
> yTemp = replace(yTemp,"|","")
> yTemp = replace(yTemp,"¬","")
> yTemp = replace(yTemp,"`","")
> yTemp = replace(yTemp,"é","e")
> yTemp = replace(yTemp,"è","e")
> yTemp = replace(yTemp,"à","a")
> yTemp = replace(yTemp,"ï","i")
> yTemp = replace(yTemp,"ê","e")
> yTemp = replace(yTemp,"â","a")
> yTemp = replace(yTemp,"ô","o")
> strString = yTemp
> End Function
>
>
>
>[/color]


Beznas
Guest
 
Posts: n/a
#3: Jul 19 '05

re: function that removes the punctuation and some characters like (*&^%$#@!<>?"} from a text string


> You may want to look into Regular Expressions, as it may be easier and[color=blue]
> faster.[/color]


Tom;

I'm not sure I got that right.
What do you mean by regular expressions? Also where do you want me to put
the CleanX=yTemp ?


Thanks a lot.



"Tom B" <shuckle@NOSPAMhotmail.com> wrote in message
news:Ob6K3$ydDHA.2168@TK2MSFTNGP09.phx.gbl...[color=blue]
> Your last line should be CleanX=yTemp
> You may want to look into Regular Expressions, as it may be easier and
> faster.
>
> "Beznas" <walou@walou.com> wrote in message
> news:%23weMnxydDHA.1772@TK2MSFTNGP10.phx.gbl...[color=green]
> > Hi All;
> >
> > I'm trying to create an ASP function called CleanX that removes the
> > punctuation and some characters like (*&^%$#@!<>?"}|{..) from a[/color]
> text[color=green]
> > string
> >
> > I came up with this but It doesn't look like it's working.
> >
> > Can anyone help please.
> > THANK YOU.
> >
> >
> > Function CleanX(strString)
> >
> > yTemp = strString
> > yTemp = replace(yTemp,"*","")
> > yTemp = replace(yTemp,"!","")
> > yTemp = replace(yTemp,"""","")
> > yTemp = replace(yTemp,"£","")
> > yTemp = replace(yTemp,"$","")
> > yTemp = replace(yTemp,"%","")
> > yTemp = replace(yTemp,"^","")
> > yTemp = replace(yTemp,"&","")
> > yTemp = replace(yTemp,"(","")
> > yTemp = replace(yTemp,")","")
> > yTemp = replace(yTemp,"_","")
> > yTemp = replace(yTemp,"-","")
> > yTemp = replace(yTemp,"=","")
> > yTemp = replace(yTemp,"+","")
> > yTemp = replace(yTemp,"#","")
> > yTemp = replace(yTemp,"~","")
> > yTemp = replace(yTemp,"[","")
> > yTemp = replace(yTemp,"{","")
> > yTemp = replace(yTemp,"]","")
> > yTemp = replace(yTemp,"}","")
> > yTemp = replace(yTemp,";","")
> > yTemp = replace(yTemp,":","")
> > yTemp = replace(yTemp,"@","")
> > yTemp = replace(yTemp,"'","-")
> > yTemp = replace(yTemp,"<","")
> > yTemp = replace(yTemp,",","")
> > yTemp = replace(yTemp,">","")
> > yTemp = replace(yTemp,".","")
> > yTemp = replace(yTemp,"?","")
> > yTemp = replace(yTemp,"/","")
> > yTemp = replace(yTemp,"\","")
> > yTemp = replace(yTemp,"|","")
> > yTemp = replace(yTemp,"¬","")
> > yTemp = replace(yTemp,"`","")
> > yTemp = replace(yTemp,"é","e")
> > yTemp = replace(yTemp,"è","e")
> > yTemp = replace(yTemp,"à","a")
> > yTemp = replace(yTemp,"ï","i")
> > yTemp = replace(yTemp,"ê","e")
> > yTemp = replace(yTemp,"â","a")
> > yTemp = replace(yTemp,"ô","o")
> > strString = yTemp
> > End Function
> >
> >
> >
> >[/color]
>
>[/color]


dlbjr
Guest
 
Posts: n/a
#4: Jul 19 '05

re: function that removes the punctuation and some characters like (*&^%$#@!<>?"} from a text string


<%
Function CleanString(strData)
strData = Trim(strData)
lngLength = Len(strData)
If lngLength > 0 Then
Dim aryResult()
Redim aryResult(lngLength - 1)
For intCount = 1 To lngLength
intItem = Asc(Mid(strData,intCount,1))
If intItem = 32 Or intItem >= 48 And intItem <= 57 Or intItem >= 65 And
intItem <= 90 Or intItem >= 97 And intItem <= 122 Then
aryResult(intCount - 1) = Chr(intItem)
End If
Next
CleanString = Trim(Join(aryResult,""))
End If
End Function
'Example
Response.Write CleanString("123 ABC abc ^&%")
%>

-dlbjr

invariable unerring alien


Evertjan.
Guest
 
Posts: n/a
#5: Jul 19 '05

re: function that removes the punctuation and some characters like (*&^%$#@!<>?"} from a text string


Beznas wrote on 10 sep 2003 in microsoft.public.inetserver.asp.general:[color=blue]
> What do you mean by regular expressions?[/color]

Function CleanX(strString)
Set regEx = New RegExp
regEx.Pattern = "[^a-z0-9 ]+"
regEx.IgnoreCase = True
regEx.Global = True
CleanX = regEx.Replace(strString, "")
End Function

response.write CleanX("123 @@()z{}ABC abc ^&%")



--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Beznas
Guest
 
Posts: n/a
#6: Jul 19 '05

re: function that removes the punctuation and some characters like (*&^%$#@!<>?"} from a text string


Thank you Everjan; dlbjr for your help.

Both your functions work great Except that I wasn't clear on my question.

Actually I'm trying to parse some text retrived from a database to an XML
file. XML doesn't like French characters such as:

éèàïêâô

So I'm trying to replace those characters with their relatives in Standard
English Characters LCID 1036 such as:

eeaieao

So I think we need 2 arrays of characters: The ones that should be replaced
and the replacements.
The function should look for any of those characters and replace it with its
relative in English.

Also remove *!£$%^&()_-=+#~[{]};:@<,>.?/\|¬`


I tried removing éèàïêâô without replacing and the output came out
nonesense.


Thank You all for your help.
I love you.




"Evertjan." <exjxw.hannivoort@interxnl.net> wrote in message
news:Xns93F2648C24D37eejj99@194.109.133.29...[color=blue]
> Beznas wrote on 10 sep 2003 in microsoft.public.inetserver.asp.general:[color=green]
> > What do you mean by regular expressions?[/color]
>
> Function CleanX(strString)
> Set regEx = New RegExp
> regEx.Pattern = "[^a-z0-9 ]+"
> regEx.IgnoreCase = True
> regEx.Global = True
> CleanX = regEx.Replace(strString, "")
> End Function
>
> response.write CleanX("123 @@()z{}ABC abc ^&%")
>
>
>
> --
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)[/color]


Evertjan.
Guest
 
Posts: n/a
#7: Jul 19 '05

re: function that removes the punctuation and some characters like (*&^%$#@!<>?"} from a text string


Beznas wrote on 10 sep 2003 in microsoft.public.inetserver.asp.general:[color=blue]
> Actually I'm trying to parse some text retrived from a database to an
> XML file. XML doesn't like French characters such as:
>
> éèàïêâô
>
> So I'm trying to replace those characters with their relatives in
> Standard English Characters LCID 1036 such as:
>
> eeaieao
>[/color]

<%
Function CleanX(strString)
Set regEx = New RegExp
regEx.Pattern = "[^a-z0-9 ]+"
regEx.IgnoreCase = True
regEx.Global = True
CleanX = regEx.Replace(strString, "")
End Function

function deleteaccents(text)
text = CleanX(text)

olds = "éèàïêâôÉÈÀÏÊÂÔ"
news = "eeaieaoEEAIEAO"

for i=1 to len(text)
c=mid(text,i,1)
n = instr(olds,c)
if n>0 then c=mid(news,n,1)
t = t & c
next
deleteaccents = t
end function

response.write deleteaccents("éèàïêâôÉÈÀÏÊÂÔ")
%>


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Beznas
Guest
 
Posts: n/a
#8: Jul 19 '05

re: function that removes the punctuation and some characters like (*&^%$#@!<>?"} from a text string


Thanks Evertjan but the output of deleteaccents is blank!!!!!!!!
Try it. Any ideas??


<%
Function CleanX(strString)
Set regEx = New RegExp
regEx.Pattern = "[^a-z0-9 ]+"
regEx.IgnoreCase = True
regEx.Global = True
CleanX = regEx.Replace(strString, "")
End Function

function deleteaccents(text)
text = CleanX(text)

olds = "éèàïêâôÉÈÀÏÊÂÔ"
news = "eeaieaoEEAIEAO"

for i=1 to len(text)
c=mid(text,i,1)
n = instr(olds,c)
if n>0 then c=mid(news,n,1)
t = t & c
next
deleteaccents = t
end function
response.write deleteaccents("éèàïêâôÉÈÀÏÊÂÔ")
%>


Evertjan.
Guest
 
Posts: n/a
#9: Jul 19 '05

re: function that removes the punctuation and some characters like (*&^%$#@!<>?"} from a text string


Beznas wrote on 10 sep 2003 in microsoft.public.inetserver.asp.general:
[color=blue]
> Thanks Evertjan but the output of deleteaccents is blank!!!!!!!!
> Try it. Any ideas??
>[/color]

Sorry, the accented chars are deleted by the clearX

Solution see the practical test:

<http://devrijehuisarts.org/test/deleteaccents.asp>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Closed Thread