stripe strings on non-ascii characters

Results 1 to 2 of 2

Thread: stripe strings on non-ascii characters

  1. #1
    Jeremy Lowery Guest

    Default stripe strings on non-ascii characters

    does anyone know any functions around that strips strings of non-ascii characters? Ive written a message board, and people tend to copy/paste things from all different kinds of sources (such as Word processors, along with all the odd-ball characters), and thus makes outputing plain-text/html emails sometimes glitch very badly. I suppose this is the problem (the odd characters), but Im not sure. anyone help me out?

  2. #2
    BalletChick Guest

    Default RE: stripe strings on non-ascii characters

    You could loop through each character, you could use Regular Expressions (RegExps) or you could use multiple replaces. (These examples allow only A-Z, a-z and 0-9, but can be extended to whatever characters you desire)<BR><BR>Here&#039s how with RegExps:<BR>========================<BR>Set reg = New RegExp<BR>reg.Pattern = "W+"<BR>strClean = reg.Replace(strDirty, "")<BR>response.write strClean & "<BR>"<BR><BR><BR>Here&#039s how with a loop:<BR>=======================<BR>for intX = 1 to len(strDirty)<BR>&nbsp;&nbsp;&nbsp;intASC = asc(mid(strDirty, intX, 1))<BR>&nbsp;&nbsp;&nbsp;if (intASC&#062;31 and intasc&#060;91) or (intASC&#062;96 and intASC&#060;123) then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#039 It&#039s OK<BR>&nbsp;&nbsp;&nbsp;else<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;strDirty = left(strDirty, intX-1) & " " & mid(strDirty, x+1)<BR>&nbsp;&nbsp;&nbsp;end if<BR>next<BR><BR>Here&#039s how with multiple replaces...<BR>=================================== ==<BR>strDirty = replace(strDirty, "=", " ")<BR>strDirty = replace(strDirty, "@", " ")<BR>strDirty = replace(strDirty, "#", " ")<BR>strDirty = replace(strDirty, "$", " ")<BR>strDirty = replace(strDirty, "%", " ")<BR> ... etc ...

Posting Permissions

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