Solved

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

Posted on 2011-03-21
5
1,029 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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

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.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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 …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

749 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