UNICODE to ANSI converter

Roy from Brook House Publishing has kindly submitted a VB procedure for converting UNICODE
to ANSI. ‘I wrote it for parsing UNICODE strings in PDF. A bit specialised
maybe, but useful nonetheless. Well it was for me anyway:)’

This code sample is posted here for the general benefit of the PDF development community. Attribution and usage guidelines are as noted in the code source; please respect the wishes of the author when using this code.

'©2000 Roy Walter, Brook House Ltd
'Please email comments to walt@brookhouse.co.uk
'* Useful routine for converting UNICODE strings to 'readable' ANSI
'* It was designed for decoding UNICODE strings in PDF files
'* You can use it and modify it but you can't sell it
'* If you redistribute do not remove this line and the lines above
Sub UnicodeToAnsi()

Dim hx, myArray
Dim c$, ansiStr$, uniStr$
Dim arrSize%, i%, loops%, n%

'example only
uniStr$ = ''
If InStr(uniStr$, 'feff') = 0 Then Exit Sub 'it's not unicode!

If Left(uniStr$, 1) = '<' Then uniStr$ = Mid(uniStr$, 2)
If Right(uniStr$, 1) = '>' Then
uniStr$ = Left(uniStr$, Len(uniStr$) - 1)
End If

i% = Len(uniStr$)
arrSize% = i% / 4
ReDim myArray(arrSize%)

For i% = 1 To Len(uniStr$) Step 4
c$ = Mid$(uniStr$, i, 4)
If c$ <> 'feff' Then
hx = '&H' &

n% = Int(hx)
myArray(loops%) =

loops% = loops% +

End If

For i% = 0 To UBound(myArray) - 1
ansiStr$ = ansStr$ & Chr(myArray(i%))

MsgBox ansiStr$

End Sub

You May Also Like

About the Author: Planet PDF Team

Leave a Reply