Solved

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

Posted on 2011-03-21
5
1,014 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
  • 3
  • 2
5 Comments
 
LVL 4

Expert Comment

by:Tuyau2poil
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This is about my first experience with programming Arduino.
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.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
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 …

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now