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

B

Beznas

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
 
T

Tom B

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

Beznas

You may want to look into Regular Expressions, as it may be easier and


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 said:
Your last line should be CleanX=yTemp
You may want to look into Regular Expressions, as it may be easier and
faster.

Beznas said:
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
 
D

dlbjr

<%
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
 
E

Evertjan.

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 ^&%")
 
B

Beznas

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 *!£$%^&()_-=+#~[{]};:mad:<,>.?/\|¬`


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


Thank You all for your help.
I love you.




Evertjan. said:
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 ^&%")
 
E

Evertjan.

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("éèàïêâôÉÈÀÏÊÂÔ")
%>
 
B

Beznas

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("éèàïêâôÉÈÀÏÊÂÔ")
%>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,091
Messages
2,570,605
Members
47,225
Latest member
DarrinWhit

Latest Threads

Top