[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How can I avoid unicode and use Latin1? (Was: Wrong characters with
From: |
stk |
Subject: |
Re: How can I avoid unicode and use Latin1? (Was: Wrong characters with jEdit) |
Date: |
Fri, 2 Sep 2005 16:49:51 -0400 (EDT) |
On Fri, 2 Sep 2005, Daniel Johnson wrote:
> I offer the following with NO WARRANTY.
Offer accepted. That's always acceptable.
> . . . . . . . . . . . . . . . . .. . . I am enclosing a VBScript file
> that should perform conversion from Latin-1 to UTF-8. I haven't tested
> this. Also, I never did figure out how to use command-line args with
> VBS, so you'll have to hardcode the input and output filenames each time
The VBScript can be modified to be work when called from an entry on
the right-click ("context") menu associated with the input file.
However, that requires messing with the Windows Registry, and
most noncommercial people are leery (as I am) of distributing material
that requires Registry changes, so in fact your script as it stands
is a very safe solution.
Being somewhat unicode-resistant, I was not familiar with the details
of conversion. I may or may not wind up using your routine, but it
makes it very clear what the characters in a unicoded file look like,
and I was unaware of that.
Thank you for such concrete and clear help.
-- Tom
*********************************************************************
> '==== begin VBScript code ====
>
> Option Explicit
>
> Dim sInFileName, sOutFileName
>
> sInFileName = "" ' Filename you wish to convert (with full path)
> sOutFileName = "" ' Filename you want for the output
>
> Dim oFSO
> Dim oInFile, sInString
> Dim oOutFile, sOutString
> Dim i, s
> Dim sTransArray(255)
>
> 'Populate the translation table
> For i = 128 To 191
> sTransArray(i) = chr(&HC2) & chr(i)
> Next
> For i = 192 To 255
> sTransArray(i) = chr(&HC3) & chr(i - 64)
> Next
>
> 'Read the input file as a single string
> Set oFSO = CreateObject("Scripting.FileSystemObject")
> Set oInFile = oFSO.OpenTextFile(sInFileName, 1, False, 0)
> sInString = oInFile.ReadAll
> oInFile.Close
> Set oInFile = Nothing
>
> 'Perform char-by-char translation
> sOutString = ""
> For i = 0 To Len(sInString)
> s = Mid(sInString, i, 1)
> If Asc(s) < 128 Then
> sOutString = sOutString & s
> Else
> sOutString = sOutString & sTransArray(Asc(s))
> End If
> Next
>
> 'Write the resulting file to the output file
> Set oOutFile = oFSO.OpenTextFile(sOutFileName, 2, True, 0)
> oOutFile.Write(sOutString)
> oOutFile.Close
>
> 'Perform final housekeeping
> Set oOutFile = Nothing
> Set oFSO = Nothing
>
> End
>
> '==== end VBScript code ====
- Re: Wrong characters with jEdit, stk, 2005/09/01
- Re: Wrong characters with jEdit, Mats Bengtsson, 2005/09/01
- How can I avoid unicode and use Latin1? (Was: Wrong characters with jEdit), stk, 2005/09/02
- Re: How can I avoid unicode and use Latin1? (Was: Wrong characters with jEdit), Mats Bengtsson, 2005/09/02
- Re: How can I avoid unicode and use Latin1? (Was: Wrong characters with jEdit), Daniel Johnson, 2005/09/02
- Re: How can I avoid unicode and use Latin1? (Was: Wrong characterswith jEdit), Hans de Rijck, 2005/09/02
- Re: How can I avoid unicode and use Latin1? (Was: Wrong characterswith jEdit), stk, 2005/09/02
- Re: How can I avoid unicode and use Latin1?, Jan Nieuwenhuizen, 2005/09/02
- Re: How can I avoid unicode and use Latin1?, stk, 2005/09/04
- Re: How can I avoid unicode and use Latin1?, Pedro Kröger, 2005/09/04
- Re: How can I avoid unicode and use Latin1? (Was: Wrong characters with jEdit),
stk <=
- Re: How can I avoid unicode and use Latin1? (Was: Wrong characters with jEdit), stk, 2005/09/04
- Re: How can I avoid unicode and use Latin1?, Jan Nieuwenhuizen, 2005/09/04
- Re: How can I avoid unicode and use Latin1? (Was: Wrong characters with jEdit), stk, 2005/09/02
- Re: How can I avoid unicode and use Latin1? (Was: Wrong characters with jEdit), Han-Wen Nienhuys, 2005/09/02
- Re: How can I avoid unicode and use Latin1? (Was: Wrong characters with jEdit), stk, 2005/09/03
- Re: How can I avoid unicode and use Latin1?, Jan Nieuwenhuizen, 2005/09/04
- Re: How can I avoid unicode and use Latin1?, Werner LEMBERG, 2005/09/04
- Re: How can I avoid unicode and use Latin1?, stk, 2005/09/05
- How can I avoid Latin1 and use UTF-8?, Hans Aberg, 2005/09/05
- Re: How can I avoid unicode and use Latin1? (Was: Wrong characters with jEdit), Han-Wen Nienhuys, 2005/09/04