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

Discussion in 'ASP General' started by Beznas, Sep 10, 2003.

  1. Beznas

    Beznas Guest

    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
     
    Beznas, Sep 10, 2003
    #1
    1. Advertising

  2. Beznas

    Tom B Guest

    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
    >
    >
    >
    >
     
    Tom B, Sep 10, 2003
    #2
    1. Advertising

  3. Beznas

    Beznas Guest

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

    >
    >
     
    Beznas, Sep 10, 2003
    #3
  4. Beznas

    dlbjr Guest

    <%
    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
     
    dlbjr, Sep 10, 2003
    #4
  5. Beznas

    Evertjan. Guest

    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)
     
    Evertjan., Sep 10, 2003
    #5
  6. Beznas

    Beznas Guest

    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." <> 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)
     
    Beznas, Sep 10, 2003
    #6
  7. Beznas

    Evertjan. Guest

    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)
     
    Evertjan., Sep 10, 2003
    #7
  8. Beznas

    Beznas Guest

    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("éèàïêâôÉÈÀÏÊÂÔ")
    %>
     
    Beznas, Sep 10, 2003
    #8
  9. Beznas

    Evertjan. Guest

    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)
     
    Evertjan., Sep 10, 2003
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?YmVhbndlZWQ=?=

    AppendChild removes like nodes?

    =?Utf-8?B?YmVhbndlZWQ=?=, Mar 1, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    350
    bruce barker
    Mar 1, 2005
  2. rote
    Replies:
    2
    Views:
    7,398
    Mark Fitzpatrick
    Jan 23, 2008
  3. Ethan Furman
    Replies:
    3
    Views:
    250
    Roel Schroeven
    Jun 17, 2008
  4. Terry Reedy
    Replies:
    4
    Views:
    371
    Terry Reedy
    Jun 17, 2008
  5. Peng Yu
    Replies:
    2
    Views:
    289
    Peter Makholm
    Dec 4, 2012
Loading...

Share This Page