Unicode Help Needed

BlitzMax Forums/BlitzMax Programming/Unicode Help Needed

Cartman(Posted 2006) [#1]
Hi all,

I have a few questions about Unicode. I'm trying to put Japanese text into my game. Here's what I'm doing.

1. I create a text file with japanese text. I confirm the text by using a font like batang.ttf so I can see it in notepad. I then save it as UTF-8 format.

2. In my code I'm using the Big Endian code that Ziggy made to bring the file data in. It seems to be getting scrambled but I don't know why.

3. If I hardcode the data from the text file into my code it shows up correctly in the game without any problem, but somehow I'm scrambling it wrong.

So here's the questions:
1. What am I doing wrong with the Big Endian code? Or should I be using something else?

2. Is UTF-8 the correct format to save the file in?

Any other suggestions you guys might have would be appreciated.

Thanks
-Keith


skidracer(Posted 2006) [#2]
If you are saving the file as utf8 then:
myunicode$=LoadText(filename.txt)

should just work.


Cartman(Posted 2006) [#3]
Thanks skidracer. That's apparently what I needed. However, that returns the whole file's contents. Before I was just reading line, by line and saving the data to an array in my program. Is there an easy way to get this functionality back once I go down this road?

Sorry for the simple question. :)


Cartman(Posted 2006) [#4]
No worries. I figured it out. I just parsed the strings with Instr, Left, and Right and got it working in about 8 lines of code. Probably easier ways to do it, but this works well. :)


ziggy(Posted 2006) [#5]
you could use the class I've implemented to read unicode files as text streams (it's based on the loadtext function of mark)

here you have it

http://www.blitzmax.com/Community/posts.php?topic=61706#690019