WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

String Manipulation

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

FixNonAscii

 Keywords: Fix NON-Ascii Ascii Replace Characters HTM HTML File Find 

#DefineFunction FixNonAscii(xfile)
   ; Version III   BinaryXLate  also possibly debugged
   ; Fast, if not instantaneous
   ; Hmmm takes 0.36 seconds on my 100K test file
   ;
   xlatetable = BinaryAlloc(256)
   For x = 0 To 127                     ; building this table each time is a slight slowdown
      BinaryPoke(xlatetable, x ,x)
      BinaryPoke(xlatetable, x+128, 255)
   Next
   fs      = FileSize(xfile)
   bborig  = BinaryAlloc(fs)
   bbxlate = BinaryAlloc(fs)
   outBB   = BinaryAlloc(fs*5+1000)
   outptr  = 0
   BinaryRead(bborig, xfile)
   BinaryRead(bbxlate, xfile)
   BinaryXlate(bbxlate, xlatetable, 0)
   CharFF  = Num2Char(255)
   ptrA    = 0
   While ptrA <= fs
         ptrZ=BinaryIndexEx(bbxlate, ptrA, CharFF, @FWDSCAN, @FALSE)
         If ptrZ   == -1   ; no more funny chars
            outptr = outptr + BinaryCopy(outBB, outptr, bborig, ptrA, fs-ptrA)
            Break
         EndIf
         ;hmmm found a funny char
         DaCharStr = BinaryPeek(bborig, ptrZ)
         outptr    = outptr + BinaryCopy(outbb, outptr, bborig, ptrA, PtrZ-PtrA )
         outptr    = outptr + BinaryPokeStr(outbb, outptr, StrCat("&#",StrFixLeft(DaCharStr, ",0", 3),";"))
         ptrA      = ptrZ + 1
   EndWhile
   BinaryWrite(outbb, xfile)
   BinaryFree(bborig)
   BinaryFree(bbxlate)
   BinaryFree(outbB)
   BinaryFree(xlatetable)
   Return
#EndFunction

Article ID:   W18388
Filename:   FixNonAscii.txt
File Created: 2009:03:12:09:07:14
Last Updated: 2009:03:12:09:07:14