Question print in chinese in text file

AJBC66

New Member
Good afternoon, I need to convert a text in Chinese and print it in a text file, that is I am reading a database that has a field in Chinese I need to read and print it in a text file, could you help me how to do it?

below some attempts

Code:
def var charsetstring as char.

  output to c:\temp\chines.txt CONVERT SOURCE "UTF-8" TARGET "BIG-5". 

// output to c:\temp\sgrest0022a.txt .
assign charsetstring = "米色".
assign charsetstring =  CODEPAGE-CONVERT(charsetstring, "UTF-8", "BIG-5").
// assign charsetstring =  CODEPAGE-CONVERT(charsetstring, "ISO8859-1", "UTF-8").

put "texto - " charsetstring.

grateful if anyone can help me
 
Last edited by a moderator:

TomBascom

Curmudgeon
Why do you need to convert the code page? If the data is already in the proper code page (you seem to imply that Chinese data already exists in your db) you shouldn't need to do any conversions.

Is there something that you aren't telling us about what code pages are in use?

COPY-LOB is also a very good way to write data to files. I.e.

Code:
find customer no-lock where custId = 123.

/* assume that customer.notes is a LOB field
 */

copy-lob customer.notes to file "chinese.out".

/* or, if not, use a longchar variable
 */

define variable n as longchar no-undo.

n = customer.notes.

copy-lob n to file "chines.out2".
 

AJBC66

New Member
the data is in a sql database, where i am reading and trying to print to a txt file, along with other data that will not be printed in chinese, only one field will be chinese.
 

TomBascom

Curmudgeon
How are you connecting to this sql database? And what code page is used when you query this sql database?
 

andre42

Member
It looks like there is more than one issue with your code.

For your example to make sense,
  • session:cpstream would have to be a Unicode capable code page and match the code page your program is stored. (This attributes tells Progress in which code page your programs are stored. Since you are writing chinese characters in your code you can't get away with something like 1252.)
  • and your session would have to be running in BIG-5. (The string is stored in session:cpinternal, and you are then converting it from BIG-5 to UTF-8.)
Both points are not exactly plausible.

Also it seems you are first converting the string from BIG-5 to UTF-8 (CODEPAGE-CONVERT in the assign statement) and then on writing the string to the file it gets converted from UTF-8 to BIG-5. Maybe this is just your example and you are actually getting a BIG-5 string from the SQL database, but currently it just looks confusing and a bit silly.
 
Top