Solved

VBScript : Convert text : "ASCII Codes" to "ISO 8859-1 Characters"

Posted on 2011-03-21
2
1,609 Views
Last Modified: 2012-05-11
Hi there,

The purpose of this script is to convert some characters within a text file.

The problem here is, for example, once it converted &H88 to &HEA, it will reconvert the same character from &HEA to &HDB.

I need this script to convert a character only once.

(I was wondering if the use of a "regular expression" would be the answer.)

Please provide full code.
 
Thanks for your help,
Rene

 
Dim Mystring,MyFile
MyFile=WScript.Arguments(0)

'get file in string
Mystring=Getfile(MyFile)

MyString=replace(MyString,chr(&HB7),chr(&HC0))
MyString=replace(MyString,chr(&H85),chr(&HE0))
MyString=replace(MyString,chr(&HB6),chr(&HC2))
MyString=replace(MyString,chr(&H83),chr(&HE2))
MyString=replace(MyString,chr(&H92),chr(&HC6))
MyString=replace(MyString,chr(&H91),chr(&HE6))
MyString=replace(MyString,chr(&H80),chr(&HC7))
MyString=replace(MyString,chr(&H87),chr(&HE7))
MyString=replace(MyString,chr(&HD4),chr(&HC8))
MyString=replace(MyString,chr(&H8A),chr(&HE8))
MyString=replace(MyString,chr(&H90),chr(&HC9))
MyString=replace(MyString,chr(&H82),chr(&HE9))
MyString=replace(MyString,chr(&HD2),chr(&HCA))
MyString=replace(MyString,chr(&H88),chr(&HEA))
MyString=replace(MyString,chr(&HD3),chr(&HCB))
MyString=replace(MyString,chr(&H89),chr(&HEB))
MyString=replace(MyString,chr(&HD7),chr(&HCE))
MyString=replace(MyString,chr(&H8C),chr(&HEE))
MyString=replace(MyString,chr(&HD8),chr(&HCF))
MyString=replace(MyString,chr(&H8B),chr(&HEF))
MyString=replace(MyString,chr(&HE2),chr(&HD4))
MyString=replace(MyString,chr(&H93),chr(&HF4))
MyString=replace(MyString,chr(&HEB),chr(&HD9))
MyString=replace(MyString,chr(&H97),chr(&HF9))
MyString=replace(MyString,chr(&HEA),chr(&HDB))
MyString=replace(MyString,chr(&H96),chr(&HFB))
MyString=replace(MyString,chr(&H9A),chr(&HDC))
MyString=replace(MyString,chr(&H81),chr(&HFC))


'write result in same file
 Dim OutStream, FS
 on error resume Next
 Set FS = CreateObject("Scripting.FileSystemObject")
 Set OutStream = FS.OpenTextFile(MyFile, 2, True)
 OutStream.Write MyString

function GetFile(FileName)
  If FileName<>"" Then
    Dim FS, FileStream
    Set FS = CreateObject("Scripting.FileSystemObject")
      on error resume Next
      Set FileStream = FS.OpenTextFile(FileName)
      GetFile = FileStream.ReadAll
  End If
End Function

Open in new window

0
Comment
Question by:ReneGe
2 Comments
 
LVL 1

Accepted Solution

by:
B34RDY earned 500 total points
ID: 35186417
I have altered your code slightly so that it won't change a character and then change it again.
It is to do with the order in which they are checked. If you look at my change you will see I have made 2 repositions of your replace code.


Dim Mystring,MyFile
MyFile=WScript.Arguments(0)

'get file in string
Mystring=Getfile(MyFile)

MyString=replace(MyString,chr(&HB7),chr(&HC0))
MyString=replace(MyString,chr(&H85),chr(&HE0))
MyString=replace(MyString,chr(&HB6),chr(&HC2))
MyString=replace(MyString,chr(&H83),chr(&HE2))
MyString=replace(MyString,chr(&H92),chr(&HC6))
MyString=replace(MyString,chr(&H91),chr(&HE6))
MyString=replace(MyString,chr(&H80),chr(&HC7))
MyString=replace(MyString,chr(&H87),chr(&HE7))
MyString=replace(MyString,chr(&HD4),chr(&HC8))
MyString=replace(MyString,chr(&H8A),chr(&HE8))
MyString=replace(MyString,chr(&H90),chr(&HC9))
MyString=replace(MyString,chr(&H82),chr(&HE9))
MyString=replace(MyString,chr(&HD2),chr(&HCA))
MyString=replace(MyString,chr(&HEA),chr(&HDB))
MyString=replace(MyString,chr(&H88),chr(&HEA))
MyString=replace(MyString,chr(&HD3),chr(&HCB))
MyString=replace(MyString,chr(&HEB),chr(&HD9))
MyString=replace(MyString,chr(&H89),chr(&HEB))
MyString=replace(MyString,chr(&HD7),chr(&HCE))
MyString=replace(MyString,chr(&H8C),chr(&HEE))
MyString=replace(MyString,chr(&HD8),chr(&HCF))
MyString=replace(MyString,chr(&H8B),chr(&HEF))
MyString=replace(MyString,chr(&HE2),chr(&HD4))
MyString=replace(MyString,chr(&H93),chr(&HF4))
MyString=replace(MyString,chr(&H97),chr(&HF9))
MyString=replace(MyString,chr(&H96),chr(&HFB))
MyString=replace(MyString,chr(&H9A),chr(&HDC))
MyString=replace(MyString,chr(&H81),chr(&HFC))


'write result in same file
 Dim OutStream, FS
 on error resume Next
 Set FS = CreateObject("Scripting.FileSystemObject")
 Set OutStream = FS.OpenTextFile(MyFile, 2, True)
 OutStream.Write MyString

function GetFile(FileName)
  If FileName<>"" Then
    Dim FS, FileStream
    Set FS = CreateObject("Scripting.FileSystemObject")
      on error resume Next
      Set FileStream = FS.OpenTextFile(FileName)
      GetFile = FileStream.ReadAll
  End If
End Function

Open in new window

0
 
LVL 10

Author Comment

by:ReneGe
ID: 35186494
Got it!

I found 2 more to reorder. Tested it and works well.

Thanks Tuyau2poil for writing script.
Thanks B34RDY for helping me resolving the issue.

Cheers,
Rene
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C# application error "Parameter Is Not Valid". 3 95
Filename to be appended with DateTimeof Download 3 55
Compile Error 7 51
Problem to With line 4 57
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question