mayayana
Thu May 10 11:13:46 CDT 2007
Please don't multi-post. You've posted this same
question separately in a VB group, which has nothing
to do with VBScript.
It sounds like you just want to filter funky
characters. They're all ascii. If it's an ANSI text file
then each byte is an ascii character. But anything
above 125 in English, I think, might be considered
funky.
(If you don't have an ascii reference you might want to
download this handy help file:
http://ourworld.compuserve.com/homepages/r_harvey/asciicat.htm
)
You can probably use RegExp for this, but personally
I find that very tedious to figure out. :) Here's one method:
----------------------------------------------------
'-- save this text as a VBS file, then
'-- drop a text file onto the VBS to clean
'-- out all funky characters.
Dim FSO, TS, sFil, s1, A1(), i2, iChar, s2
sFil = WScript.arguments(0)
Set FSO = CreateObject("Scripting.FileSystemObject")
Set TS = FSO.OpenTextFile(sFil, 1)
s1 = TS.ReadAll
TS.Close
Set TS = Nothing
ReDim A1(len(s1) - 1)
For i2 = 0 to UBound(A1)
s2 = Mid(s1, (i2 + 1), 1)
iChar = Asc(s2)
If (iChar < 9) Or ((iChar > 13) And (iChar < 32)) Or (iChar > 125) Then
A1(i2) = Chr(1)
Else
A1(i2) = s2
End If
Next
s1 = Join(A1, "")
s1 = Replace(s1, chr(1), "")
Set TS = FSO.CreateTextFile(sFil, True)
TS.Write s1
TS.Close
Set TS = Nothing
Set FSO = Nothing
--------------------------------