WritePreferenceString and UTF8
WritePreferenceString and UTF8
The default WritePreferenceString writes to UTF BOM. How to make it writes to UTF8 without BOM?
Re: WritePreferenceString and UTF8
Edit: This is not true: As far as I know that is not possible. .....
Some hints (anyway):
You can use CreateFile or OpenFile with WriteXxxx or the xml or json file functions.
You can also use any of the (kind of) INI file modules (on the forum) or on github......
A small collection:
Sicro's PB-CodeArchiv-Rebirth
Kenmo's Includes
RSBasic's WinAPI Library
Some hints (anyway):
You can use CreateFile or OpenFile with WriteXxxx or the xml or json file functions.
You can also use any of the (kind of) INI file modules (on the forum) or on github......
A small collection:
Sicro's PB-CodeArchiv-Rebirth
Kenmo's Includes
RSBasic's WinAPI Library
Last edited by Axolotl on Wed Mar 05, 2025 12:19 pm, edited 1 time in total.
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
Re: WritePreferenceString and UTF8
CreatePreferences + #PB_Preference_NoBOM
Re: WritePreferenceString and UTF8
Upps, I missed that new Flag. So AZJIO is right the flag #PB_Preference_NoBOM worked.
I use the OpenPreferences() for reading and writing and with it you always get the BOM, because the flag is not possible here.
I use the OpenPreferences() for reading and writing and with it you always get the BOM, because the flag is not possible here.
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
Re: WritePreferenceString and UTF8
Check by creating ini in UTF8 format without BOM. Theoretically, Openpreferences () should not add BOM.Axolotl wrote: Wed Mar 05, 2025 12:15 pm I use the OpenPreferences() for reading and writing and with it you always get the BOM, because the flag is not possible here.
Look in the reference file:
#PB_Ascii: The file will be read as Ascii, unless there an UTF-8 BOM. If the preferences are written back to file, it will be using UTF-8.
Re: WritePreferenceString and UTF8
I need to write to an existing file. And if I use CreatePreferences + #PB_Preference_NoBOM then the file will be overwritten and its contents will disappear.
Re: WritePreferenceString and UTF8
I tried this method. The file still converts to UTF8 BOM if I use WritePreferenceString.AZJIO wrote: Wed Mar 05, 2025 12:30 pm Check by creating ini in UTF8 format without BOM. Theoretically, Openpreferences () should not add BOM.
Look in the reference file:
Re: WritePreferenceString and UTF8
Then you need to contact Fred to add #PB_Preference_NoBOM for OpenPreferences.
I had a file with Russian text (UTF-8 without BOM) opened apparently as Ascii, but when writing a new parameter UTF-8 + BOM was added and I got broken text.
Use WinAPI for now. But the ANSI or UTF16 file format
I had a file with Russian text (UTF-8 without BOM) opened apparently as Ascii, but when writing a new parameter UTF-8 + BOM was added and I got broken text.
Use WinAPI for now. But the ANSI or UTF16 file format
Code: Select all
WritePrivateProfileString_(Section, Key, Value, Path)
Re: WritePreferenceString and UTF8
Well, ......
Here Fred wrote that the Preference library is only for PB applications.
PB 6.10 b1 - OpenPreference()
So, I follow the "rules" and use the Preferences Library for PB stuff only.
The advantage of OpenPreferences() compared to CreatePreferences() for me is, that you can do partial update.
In all other cases I try my best with functions I mentioned in my first post above.
Here Fred wrote that the Preference library is only for PB applications.
PB 6.10 b1 - OpenPreference()
So, I follow the "rules" and use the Preferences Library for PB stuff only.
The advantage of OpenPreferences() compared to CreatePreferences() for me is, that you can do partial update.
In all other cases I try my best with functions I mentioned in my first post above.
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
Re: WritePreferenceString and UTF8
Yes, I am in the knowAxolotl wrote: Wed Mar 05, 2025 1:22 pm Here Fred wrote that the Preference library is only for PB applications.
Linux uses UTF8 files without BOM because the system does not support Ascii. And it's not that hard to add, all you have to do is disable BOM writing to the file. I don't think it requires complex code.
Code: Select all
If Not #PB_Preference_NoBOM
WriteStringFormat(#File, #PB_UTF8)
EndIf
https://www.purebasic.fr/english/viewtopic.php?t=78105 (There is a solution from mk-soft)
https://www.purebasic.fr/english/viewtopic.php?t=83196