Jump to content
Sign in to follow this  
Genos

Writing Japanese characters to a file

Recommended Posts

Genos

I'm attempting to take user input and write that input into a file.

The input includes japanese characters, but when I view the file the japanese text shows up only as ?s.

Is there a way to store japanese characters?

global $saveFilePath = FileSaveDialog("Save File", "", "Fcards deck (*.fcd)",2) & ".fcd"
            
            $saveFile = FileOpen ( $saveFilePath, 130 )
            FileWriteLine($saveFile, "[Program Information]")
            FileWriteLine($saveFile, "Title = " & GUICtrlRead($txtTitle, 1))
            FileWriteLine($saveFile, "Description = " & GUICtrlRead($txtDescription, 1))
            FileWriteLine($saveFile, "Author = " & GUICtrlRead($txtAuthor, 1))
            FileWriteLine($saveFile, "Version = " & GUICtrlRead($txtVersion, 1))
            FileWriteLine($saveFile, "WebSite = " & GUICtrlRead($txtWebSite, 1))
            FileWriteLine($saveFile, "")
            FileWriteLine($saveFile, "[Vocab]")
            $count = _GUICtrlListBox_GetCount($lstQuestion)
            $i = 0
            while $i < $count
                FileWriteLine($saveFile, "que" & $i +1 & " = " & _GUICtrlListBox_GetText($lstQuestion,$i))
                FileWriteLine($saveFile, "ans" & $i +1 & " = " & _GUICtrlListBox_GetText($lstAnswer,$i))
                $i += 1
            WEnd

The Result is:

[Program Information]
Title = Japanese Numbers
Description = Japanese Numbers, 1-100. Hiragana
Author = Genos
Version = 1.0
WebSite = http://

[Vocab]
que1 = 1
ans1 = ??
que1 = 2
ans1 = ?
que1 = 3
ans1 = ??
que1 = 4
ans1 = ??
que1 = 5
ans1 = ?
que1 = 6
ans1 = ??
que1 = 7
ans1 = ??
que1 = 8
ans1 = ??
que1 = 9
ans1 = ???
que1 = 10
ans1 = ???

The ?? should be

いち

さん

etc..

I have tried opening the file in UTF8 and just regularly, but can't get it to show correctly in the file.

Is there anyway for me to have AutoIt store japanese characters in a file using FileWriteLine()?

Thanks in advance for your help.

Share this post


Link to post
Share on other sites
KaFu
Genos

Switching SciTE to UCS-2 Little Endian and using fileopen with switch set to 34 works for me.

Thanks for the response. I don't know what you mean by "Switching SciTE to UCS-2 Little Endian". How would I do this?

Share this post


Link to post
Share on other sites
Genos

Ok, so in ScITE I did File -> Endoding -> UCS2-Little Endian, and used $saveFile = FileOpen ( $saveFilePath, 34 )

This did not work for me. Is this what you were recommending or did I do something else wrong?

thanks again in advance.

Share this post


Link to post
Share on other sites
KaFu

Yep, using UCS2-Little Endian in SciTE and fileopen with 34, this write the japanese chars to a text file correctly for me... though they are still not displayed correctly in the GUI! Maybe someone else can give input on this?

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Local $msg

GUICreate("My GUI") ; will create a dialog box that when displayed is centered
$input = GUICtrlCreateInput("いち", 10, 10, 100)
$button = GUICtrlCreateButton("Write", 120, 10, 100)
GUISetState(@SW_SHOW) ; will display an empty dialog box

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()

    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    If $msg = $button Then
        $saveFile = FileOpen("test.txt", 34)
        FileWriteLine($saveFile, GUICtrlRead($input))
        FileClose($saveFile)

    EndIf
WEnd
GUIDelete()
Edited by KaFu

Share this post


Link to post
Share on other sites
Genos

Thanks, I appreciate the help.

After running your code and seeing that it worked great (thanks!), I decided to check my method of obtaining the data from the listbox. Using

_GUICtrlListBox_GetText($lstQuestion,$i)
would result in reading ?? (verified by creating a popup with the data obtained from GetText). So I have found a workaround by using
FileWriteLine($saveFile, "ans" & $i +1 & " = " & guictrlread($lstAnswer,1))

The only problem with this is that I have to set each item to selected using

_guictrllistbox_setcursel($lstAnswer, $i)
but it now reads, writes, and displays the japanese font.

Thanks for your help >_<

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×