Re: UTF-8 to Latin-1 Conversion

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



On Mar 8, 2:11 am, "JJ" <jim.mca...@xxxxxxxxx> wrote:
Does anyone have a VBScript routine for converting strings from UTF-8
to Latin-1 (ISO-8859-1) character set?

I think I figured it out. This will handle all one and two-byte
codes, which I believe are all that can be translated into ISO-8859-1.

Function UTF8toLatin1(ByVal s)
Dim t, i, a
For i = 1 To Len(s)
a = Asc(Mid(s, i, 1))
If a <= 127 Then
t = t & Chr(a)
ElseIf a >= 194 And a <= 223 And i < Len(s) Then
i = i + 1
t = t & Chr((a And 31)*64 + (Asc(Mid(s, i, 1)) And 63))
End If
Next
UTF8toLatin1 = t
End Function

.



Relevant Pages

  • Re: Ligatures [was: Re: The -s plural in English nouns]
    ... Posting with a "Content-Type" header that falsely advertises a wrong character set cannot be considered very "succesful" communication, even though it might sometimes work just by pure coincidence. ... If your headers say "ISO-8859-1" when you're actually posting Windows CP 1252 character codes, you should do something about this discrepancy - either change the header to match the character set you're using, or pay attention and refrain from using those characters that only exist in CP 1252 but not in ISO-8859-1. ...
    (alt.usage.english)
  • Re: archic character in inputrc
    ... The predominant character set encoding of present-day computers. ... codes used fewer. ... ANSI, ...
    (comp.os.linux)
  • Re: xmlrpclib and decoding entity references
    ... the client is Cold Fusion. ... with latin-1 codes shows undefined-char boxes for codes 0x7f-0x9f. ... > def echo: ...
    (comp.lang.python)
  • Re: Attention: European C/C++/C#/Java Programmers-Call for Input
    ... 8-bit character set, you'll probably have to ignore Cyrillic and Greek, ... Latin-1 and Latin-2 taken together have about 280 ... Also they have omitted Greek and Cyrillic Aand B ... the international reference version of ISO Publication 646." ...
    (comp.arch.embedded)
  • UTF-8 to Latin-1 Conversion
    ... Does anyone have a VBScript routine for converting strings from UTF-8 ... to Latin-1 character set? ... I've looked at things like ChrW, but can't figure out how exactly it ...
    (microsoft.public.scripting.vbscript)