?
Solved

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

Posted on 2011-03-21
2
Medium Priority
?
1,707 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

762 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