B4J Question What is lastest version of jStringUtils ?

pmt

Member
Licensed User
I have problem about UTF8 when use SaveCSV/SaveCSV2.

After save CSV file I try to open with Notepad , Excel , OpenOffice.

Before add BOM:
-Open with Notepad .... Read Correct.
-Open with Excel .... Read Not Correct !!!.
-Open with OpenOffice.... Read Not Correct !!!.

After add BOM:
-Open with Notepad .... Read Correct.
-Open with Excel .... Read Correct.
-Open with OpenOffice.... Read Not Correct !!!.


I use jStringUtils version 1.00 and B4J 5.90

I tried to search new version , but I can not find.

Is there a new version save CSV correct for all applications which support CSV?


Regards,
PMT
 

Cableguy

Expert
Licensed User
I have problem about UTF8 when use SaveCSV/SaveCSV2.

After save CSV file I try to open with Notepad , Excel , OpenOffice.

Before add BOM:
-Open with Notepad .... Read Correct.
-Open with Excel .... Read Not Correct !!!.
-Open with OpenOffice.... Read Not Correct !!!.

After add BOM:
-Open with Notepad .... Read Correct.
-Open with Excel .... Read Correct.
-Open with OpenOffice.... Read Not Correct !!!.


I use jStringUtils version 1.00 and B4J 5.90

I tried to search new version , but I can not find.

Is there a new version save CSV correct for all applications which support CSV?


Regards,
PMT
Current version of B4J is 6.30, so you are a bit behind.... JStringUtils, if I remember correctly, is part of the core libs... so with the latest IDE all core kind are uptodate
 
Upvote 0

pmt

Member
Licensed User
It has nothing to do with jStringUtils version.

StringUtils.SaveCSV creates UTF8 encoded CSV files. Without BOM. If you need other encoding then it will require some very simple work.

Thank you for your reply .

My data is Asian Language after I use StringUtils.SaveCSV I can't correctly read it.

( I tried Excel and save my data as CSV and read for all programs , all read correctly as original data. )

I found solution here:

B4X:
StringUtils.SaveCSV(...)
Dim s As String = File.ReadString (...)' read the file
s = Chr(0xFEFF) & s 'add BOM
File.WriteString(..., s)

But some programs can correctly read , some programs can't .

How to fix it ?

Regards,
PMT
 
Upvote 0

pmt

Member
Licensed User
How to save csv as ANSI (windows-874 , iso-8859-11 , tis-620)

I try like this ( B4J).

B4X:
su.SaveCSV2(File.DirApp, fileName, ",", Items, headers)
Dim s As String = File.ReadString(File.DirApp, fileName)
Dim data() As Byte = s.GetBytes("windows-874")   ' and I also try iso-8859-11 , tis-620
s= BytesToString(data,0,data.Length,"windows-874")

's = Chr(0xFEFF) & s 'Add BOM
File.WriteString(File.DirApp, fileName, s)

It' s not work , it 's still encode as UTF-8.

Regards,
PMT
 
Upvote 0

pmt

Member
Licensed User
File.WriteString uses UTF8 encoding to encode the text.

B4X:
Dim data() As Byte = ...
File.WriteBytes(File.DirApp, filename, data) 'Don't use File.DirApp if you plan to create an installer. Use File.DirData instead

Another option is to use TextWriter. File.WriteBytes is neater.

I can not tried this
B4X:
File.WriteBytes(File.DirApp ,  fileName,data)

Because I use jRandomAccessFile (2.30) and no function File.WriteBytes(...).

So I tried this
B4X:
Dim out As OutputStream = File.OpenOutput(File.DirApp, fileName, False)
            out.WriteBytes(data, 0, data.Length)
            out.Close

Now it's work.

Thanks you.
PMT
 
Upvote 0
Top