Problem with Arabic language and Writeln

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
sfrattini
Newbie
Posts: 4
Joined: Fri Aug 23, 2013 10:01 am
Location: Spain

Problem with Arabic language and Writeln

Post by sfrattini » Sat Mar 25, 2017 6:09 pm

Hello,

hope you can help. I have an issue when manipulating text with arabic and chinese characters.
reading from file into variable no problem, manipulating variable also totally fine but when it is time to write a text file I get in trouble...
Here is an example:

Code: Select all


let>variable_1=Abdullah Al Rowaished Habes Nafsak عبد الله الرويشد - حابس نقسك
Let>WLN_NOCRLF=0
WriteLn>E:\Test\Arabic test.txt,nWLNRes,variable_1

produces this:

Code: Select all

Abdullah Al Rowaished Habes Nafsak ??? ???? ??????? - ???? ????
Any idea?
many thanks!

User avatar
Djek
Pro Scripter
Posts: 147
Joined: Sat Feb 05, 2005 11:35 pm
Location: Holland
Contact:

Re: Problem with Arabic language and Writeln

Post by Djek » Sun Mar 26, 2017 8:43 pm

hi,

standard text save, is ANSI formatted. So if have to save something in "strange" chars, then you might try Unicode format to save.
But writeln does not support (or i dont know it) Unicode format.

I had a similar problem saving Label specifications for food products.
I use a workaround, i abused an example Marcus showed us:
viewtopic.php?f=2&t=9260#p40503

Code: Select all

VBSTART
Dim JSEngine
Set JSEngine = CreateObject("MSScriptControl.ScriptControl")
    JSEngine.Language = "JScript"
Function UrlEncode(s)
    UrlEncode = JSEngine.CodeObject.encodeURIComponent(s)
    UrlEncode = Replace(UrlEncode, "'", "%27")
    UrlEncode = Replace(UrlEncode, """", "%22")
End Function
Function UrlDecode(s)
    UrlDecode = Replace(s, "+", " ")
    UrlDecode = JSEngine.CodeObject.decodeURIComponent(UrlDecode)
End Function
VBEND

let>filesave=C:\Beheer\Arabic test.txt
DeleteFile>filesave
let>variable_1=Abdullah Al Rowaished Habes Nafsak عبد الله الرويشد - حابس نقسك

MessageModal>original data:%CRLF%%variable_1%
//encode variable_1
VBEval>URLEncode("%variable_1%"),encData

//save to file
WriteLn>filesave,nWLNRes,encData

//ExecuteFile>filesave
//read from file
ReadLn>filesave,1,decData
//decode variable_1
VBEval>URLDecode("%decData%"),variable_1

MessageModal>retreived data:%CRLF%%variable_1%
so this way you can save your "strange" characters and read it later on
Hope this is useable ,
kind regards,
Djek

User avatar
Marcus Tettmar
Site Admin
Posts: 7378
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Problem with Arabic language and Writeln

Post by Marcus Tettmar » Mon Mar 27, 2017 10:34 am

WriteLn supports UTF8:

Let>WLN_ENCODING=UTF8
WriteLn>....

Obviously (I hope) this won't affect an existing file, so if you are just writing to the end of an existing file this won't change that file's encoding, but if you are writing a new file it will be UTF8 encoded.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

sfrattini
Newbie
Posts: 4
Joined: Fri Aug 23, 2013 10:01 am
Location: Spain

Re: Problem with Arabic language and Writeln

Post by sfrattini » Tue Apr 11, 2017 5:29 am

Hello both, sorry for late reply and thanks for your suggestions.
Unfortunately WLN_ENCODING=UTF8 seems not to be working (I tried with new files and existing UTF8 encoded ones..) and the first suggestion does not solve the problem of writing a file with these UTF variables.
What I am doing is:
1. Read from a webpage in arabic-chinese text
2. Save onto a variable
3. reformatting, manipulating it
4. save into a different text file the result

now, 1-2-3 seem ok. 4 is the issue.
I wonder if there is a workaround to write a file other than WriteLn which seems to be the problem here, maybe if you can suggest a VBscript that does a similar action to WriteLn would work
Any additional help is very welcome.

sfrattini
Newbie
Posts: 4
Joined: Fri Aug 23, 2013 10:01 am
Location: Spain

Re: Problem with Arabic language and Writeln

Post by sfrattini » Thu Apr 13, 2017 6:50 am

Bingo with VBScript, WriteLn seems buggy, possible?

Code: Select all


let>text_to_write=Abdullah Al Rowaished Habes Nafsak عبد الله الرويشد - حابس نقسك

VBSTART

Function VBWriteLn(s)
Dim objStream
Set objStream = CreateObject("ADODB.Stream")
objStream.CharSet = "utf-8"
objStream.Open
objStream.WriteText s
objStream.SaveToFile "E:\Test\Arabic test.txt", 2
End Function

VBEND

VBEval>VBWriteLn("%text_to_write%"),writeln_result

User avatar
Djek
Pro Scripter
Posts: 147
Joined: Sat Feb 05, 2005 11:35 pm
Location: Holland
Contact:

Re: Problem with Arabic language and Writeln

Post by Djek » Thu Apr 13, 2017 7:17 am

hi Stefano,
try this:

Code: Select all

let>WLN_ENCODING=UNICODE
DeleteFile>c:\beheer\Arabic test.txt
let>variable_1=Abdullah Al Rowaished Habes Nafsak عبد الله الرويشد - حابس نقسك
WriteLn>c:\beheer\Arabic test.txt,nWLNRes,variable_1
ExecuteFile>c:\beheer\Arabic test.txt
kind regards,
Djek

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts