Solved

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

Posted on 2011-03-21
2
1,674 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
The viewer will learn how to dynamically set the form action using jQuery.
Simple Linear Regression

726 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