Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > function that removes the punctuation and some characters like (*&^%$#@!<>?"} from a text string

Reply
Thread Tools

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

 
 
Beznas
Guest
Posts: n/a
 
      09-09-2003
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




 
Reply With Quote
 
 
 
 
Tom B
Guest
Posts: n/a
 
      09-10-2003
Your last line should be CleanX=yTemp
You may want to look into Regular Expressions, as it may be easier and
faster.

"Beznas" <> wrote in message
news:%...
> 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
>
>
>
>



 
Reply With Quote
 
 
 
 
Beznas
Guest
Posts: n/a
 
      09-10-2003
> You may want to look into Regular Expressions, as it may be easier and
> faster.



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" <> wrote in message
news:Ob6K3$...
> Your last line should be CleanX=yTemp
> You may want to look into Regular Expressions, as it may be easier and
> faster.
>
> "Beznas" <> wrote in message
> news:%...
> > 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
> >
> >
> >
> >

>
>



 
Reply With Quote
 
dlbjr
Guest
Posts: n/a
 
      09-10-2003
<%
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


 
Reply With Quote
 
Evertjan.
Guest
Posts: n/a
 
      09-10-2003
Beznas wrote on 10 sep 2003 in microsoft.public.inetserver.asp.general:
> What do you mean by regular expressions?


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)
 
Reply With Quote
 
Beznas
Guest
Posts: n/a
 
      09-10-2003
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." <> wrote in message
news:Xns93F2648C24D37eejj99@194.109.133.29...
> Beznas wrote on 10 sep 2003 in microsoft.public.inetserver.asp.general:
> > What do you mean by regular expressions?

>
> 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)



 
Reply With Quote
 
Evertjan.
Guest
Posts: n/a
 
      09-10-2003
Beznas wrote on 10 sep 2003 in microsoft.public.inetserver.asp.general:
> 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
>


<%
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)
 
Reply With Quote
 
Beznas
Guest
Posts: n/a
 
      09-10-2003
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("éèàïêâôÉÈÀÏÊÂÔ")
%>


 
Reply With Quote
 
Evertjan.
Guest
Posts: n/a
 
      09-10-2003
Beznas wrote on 10 sep 2003 in microsoft.public.inetserver.asp.general:

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


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)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in running a basic code in python 3.3.0 that includes HTML file Satabdi Mukherjee Python 1 04-04-2013 07:48 PM
How get all digits, letters and punctuation characters in perl? Peng Yu Perl Misc 2 12-04-2012 09:44 AM
'string'.strip(chars)-like function that removes from the middle? Ethan Furman Python 3 06-17-2008 06:34 PM
Re: 'string'.strip(chars)-like function that removes from the middle? Terry Reedy Python 4 06-17-2008 05:51 PM
'' is not a valid name. Make sure that it does not include invalid characters or punctuation and that it is not too long. rote ASP .Net 2 01-23-2008 03:07 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57