How to replace -special character

Results 1 to 2 of 2

Thread: How to replace -special character

  1. #1
    Join Date
    Dec 1969

    Default How to replace -special character

    Need help.<BR><BR>mystring ="a%^*^s6%^&**;drt#$%&:D%&DADN&#060;MN*&;"<BR><BR> Pattern of special charater is not fixed. I want to replace<BR>all occurance of special character.<BR><BR>Thanks,<BR>ana<BR><BR>

  2. #2
    Richard A. Lowe Guest

    Default RE: How to replace -special character

    Sorry for the code dump, but you can plug-n-play this function that I wrote a while ago. It replaces diacritical characters, you can add lines to the <BR><BR>pat(0) = Array("[À-Å]{1}", "A")<BR><BR>part to replace other characters, just put them inside the [] as this array is a regular expression.<BR><BR>&#039 ~~~ FUNCTION TO RETURN (MOSTLY) ASCII-ONLY TEXT<BR>function ASCIIText(inputString)<BR> Dim pat(16) &#039 THE PATTERNS<BR> Dim regEx &#039 THE REGULAR EXPRESSION OBJ<BR> Dim tmpString &#039 TEMP STRING<BR> Dim i &#039 COUNTER<BR> tmpString = inputString<BR><BR>&#039 ~~~ MAP THE ANSI CHARACTERS TO CONVERT<BR>&#039 ~~~ STORE EACH ARRAY IN AN ARRAY<BR> pat(0) = Array("[À-Å]{1}", "A")<BR> pat(1) = Array("[*-å]{1}", "a")<BR> pat(2) = Array("[È-Ë]{1}", "E")<BR> pat(3) = Array("[è-ë]{1}", "e")<BR> pat(4) = Array("[Ì-Ï]{1}", "I")<BR> pat(5) = Array("[ì-ï]{1}", "i")<BR> pat(6) = Array("[ØÒ-Ö]{1}", "O")<BR> pat(7) = Array("[ðøò-ö]{1}", "o")<BR> pat(8) = Array("[Ù-Ü]{1}", "U")<BR> pat(9) = Array("[ù-ü]{1}", "u")<BR> pat(10) = Array ("[ýÿ]{1}", "y")<BR> pat(11) = Array("[Ÿ¥Ý]{1}", "Y")<BR> pat(12) = Array("[Ñ]{1}", "N")<BR> pat(13) = Array("[ñ]{1}", "n")<BR> pat(14) = Array("[Ç]{1}", "C")<BR> pat(15) = Array("[ç]{1}", "c")<BR><BR>&#039 ~~~ CREATE REGEXP OBJ AND SET PROPERTIES<BR><BR> Set regEx = New RegExp<BR> regEx.IgnoreCase = False &#039 Set case insensitivity.<BR> regEx.Global = True<BR><BR>&#039 ~~~ LOOP THROUGH EACH PATTERN AND<BR> for i = 0 to Ubound(pat)-1<BR> regEx.Pattern = pat(i)(0) &#039 SET THE PATTERN<BR> tmpString = regEx.Replace(tmpString, pat(i)(1) & " ") &#039 REPLACE<BR> Next<BR> ASCIIText = tmpString &#039 RETURN<BR>end function

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts