Solved

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

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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 lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …

895 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