Solved

VBScript: Convert text "alt codes" to "HTML Codes for French"

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

I need a VBScript that will scan a file and replace the french "alt code" caracters to "HTML Codes for French"

SUGGESTED REFERENCES (BUT NOT LIMMITED TO):
- FRENCH ALT CODES: http://tlt.its.psu.edu/suggestions/international/bylanguage/french.html
- HTML CODES: http://webdesign.about.com/od/localization/l/blhtmlcodes-fr.htm

SAMPLES:
FRENCH ALT CODES: ‚liminer a donc ‚t‚ effectu‚e.
FIXED: éliminer a donc été effectuée.

WILL BE STARTED FROM THE FOLLOWING COMMAND LINE:
cscript ConvertText.vbs "C:\test folder\TextToConvert.txt"

Thanks for your help,
Rene
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
  • 3
  • 2
5 Comments
 
LVL 4

Expert Comment

by:Tuyau2poil
ID: 35184139
You may put file in a string, replace characters and rewrite file :

try this sample :


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

'get file in string
Mystring=Getfile(MyFile)

MyString=replace(MyString,"À","À")
MyString=replace(MyString,"à","à")
MyString=replace(MyString,"Â","Â")
MyString=replace(MyString,"â","â")
MyString=replace(MyString,"Æ","Æ")
MyString=replace(MyString,"æ","æ")
MyString=replace(MyString,"Ç","Ç")
MyString=replace(MyString,"ç","ç")
MyString=replace(MyString,"È","È")
MyString=replace(MyString,"è","è")
MyString=replace(MyString,"É","É")
MyString=replace(MyString,"é","é")
MyString=replace(MyString,"Ê","Ê")
MyString=replace(MyString,"ê","ê")
MyString=replace(MyString,"Ë","Ë")
MyString=replace(MyString,"ë","ë")
MyString=replace(MyString,"Î","Î")
MyString=replace(MyString,"î","î")
MyString=replace(MyString,"Ï","Ï")
MyString=replace(MyString,"ï","ï")
MyString=replace(MyString,"Ô","Ô")
MyString=replace(MyString,"ô","ô")
MyString=replace(MyString,"Œ","Œ")
MyString=replace(MyString,"œ","œ")
MyString=replace(MyString,"Ù","Ù")
MyString=replace(MyString,"ù","ù")
MyString=replace(MyString,"Û","Û")
MyString=replace(MyString,"û","û")
MyString=replace(MyString,"Ü","Ü")
MyString=replace(MyString,"ü","ü")
MyString=replace(MyString,"«","«")
MyString=replace(MyString,"»","»")
MyString=replace(MyString,"€","€")

'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

0
 
LVL 10

Author Comment

by:ReneGe
ID: 35185178
Tuyau2poil,

I tried your script and it does convert french caracters to the "HTML Friendly Code" as you scripted.

However, I now realized that it will require to replace the "HEX Code" of the caracters.

For example, in the text file, "é" is represented by the ALT HEX code "82"(Alt code 130) and will need to be changed to the ISO HEX code "E9".

So I guess that my suggested links as references were not that good after all.

Thanks and cheers,
Rene
CAR	REPLACE	BY
À	B7	C0
à	85	E0
Â	B6	C2
â	83	E2
Æ	92	C6
æ	91	E6
Ç	80	C7
ç	87	E7
È	D4	C8
è	8A	E8
É	90	C9
é	82	E9
Ê	D2	CA
ê	88	EA
Ë	D3	CB
ë	89	EB
Î	D7	CE
î	8C	EE
Ï	D8	CF
ï	8B	EF
Ô	E2	D4
ô	93	F4
Ù	EB	D9
ù	97	F9
Û	EA	DB
û	96	FB
Ü	9A	DC
ü	81	FC

Open in new window

0
 
LVL 4

Accepted Solution

by:
Tuyau2poil earned 500 total points
ID: 35185518
try to change replace lines with :

MyString=replace(MyString,chr(130),chr(233))

or

MyString=replace(MyString,chr(&H82),chr(&HE9))

and so on with all french characters.
0
 
LVL 10

Author Comment

by:ReneGe
ID: 35185929
It did work.

I need to fine tune the Hex codes fore caracters but i'm good here.

Thanks a lot for your help Tuyau2poil.

Cheers,
Rene
0
 
LVL 10

Author Comment

by:ReneGe
ID: 35186296
Hey Tuyau2poil,

I found a bug in the script, so I opened a new thread.

I let you know in case you are interrested to resolve it.

http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_26902340.html

Thanks and 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

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…
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…
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 …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

691 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