?
Solved

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

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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
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