Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
0 registered members (), 18,767 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
file_str_write doesn't support unicode #419553
03/11/13 15:29
03/11/13 15:29
Joined: Nov 2012
Posts: 62
Istanbul
T
Talemon Offline OP
Junior Member
Talemon  Offline OP
Junior Member
T

Joined: Nov 2012
Posts: 62
Istanbul
Hey there, I need to write some unicode text to a text file but it seems to me that file_str_write does not support unicode strings. Is there a way to accomplish this or do I need to write my strings byte by byte?

Re: file_str_write doesn't support unicode [Re: Talemon] #419563
03/11/13 18:09
03/11/13 18:09
Joined: Aug 2008
Posts: 394
Germany
Benni003 Offline
Senior Member
Benni003  Offline
Senior Member

Joined: Aug 2008
Posts: 394
Germany
Hi Talemon,

just go to this post: Unicode text to string

Re: file_str_write doesn't support unicode [Re: Benni003] #419578
03/12/13 07:36
03/12/13 07:36
Joined: Nov 2012
Posts: 62
Istanbul
T
Talemon Offline OP
Junior Member
Talemon  Offline OP
Junior Member
T

Joined: Nov 2012
Posts: 62
Istanbul
Originally Posted By: Benni003
Hi Talemon,

just go to this post: Unicode text to string

Hey there, I'm talking about writing unicode strings to a file, not reading. I'm juggling with unicode strings now, it's just that I'm having trouble writing them.

Aynways, I wrote some utility functions to do the job, in case anyone needs:

Code:
function U_file_str_write(FILE* arg_fp, STRING* arg_str)
{
	if(U_Assert(arg_fp, "U_file_str_write: arg_fp") != 0) return;
	if(U_Assert(arg_str, "U_file_str_write: arg_str") != 0) return;
	int i;
	for(i = 0; i < str_len(arg_str) * 2; i++)
	{
		var ch = (arg_str->chars)[i];
		file_asc_write(arg_fp, ch);
	}
}

function U_file_str_writeline(FILE* arg_fp, STRING* arg_str)
{
	if(U_Assert(arg_fp, "U_file_str_write: arg_fp") != 0) return;
	U_file_str_write(arg_fp, arg_str);
	file_asc_write(arg_fp, 0x0a); // \n first byte
	file_asc_write(arg_fp, 0x00); // \n second byte
}

function U_file_str_writebom(FILE* arg_fp)
{
	if(U_Assert(arg_fp, "U_file_str_writebom: arg_fp") != 0) return;
	file_asc_write(arg_fp, 0xff); \\ 
	file_asc_write(arg_fp, 0xfe); \\ Byte-order mark(BOM) for UCS-2 LE
}

FILE* U_file_create_write(char* arg_filename)
{
	FILE* fp = file_open_write(arg_filename);
	U_file_str_writebom(fp);
	return fp;
}


Re: file_str_write doesn't support unicode [Re: Talemon] #419600
03/12/13 13:06
03/12/13 13:06
Joined: Jul 2000
Posts: 28,024
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 28,024
Frankfurt
If you have the unicode text already, you can also write it to a file with Word: Save As, File Type: Text, Coding: Unicode.


Moderated by  old_bill, Tobias 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1