Writing unicode files

Things you’d like to miss in the future...
Forum rules
:warnred20: :warnred20: :warnred20: :warnred20: :warnred20: READ THIS AND DO IT!!! :warnred20: :warnred20: :warnred20: :warnred20: :warnred20:

:info: Please include the following information:
1) Your XYplorer Version (e.g., v28.00.0801)
2) Your Windows Version (e.g., Win 11)
3) Your Screen Scaling Percentage (e.g., 125%).

:info: We strongly recommend adding your Windows Version and Screen Scaling Percentage to the Location field in your Profile or to your Signature. That way, you only have to type them once, and we won't have to search for that vital information.

:info: When attaching an Image, please use the Attachment tab at the bottom of your post and click "Add files".

:warnred20: :warnred20: :warnred20: :warnred20: :warnred20: READ THIS AND DO IT!!! :warnred20: :warnred20: :warnred20: :warnred20: :warnred20:
Post Reply
MBaas
Posts: 692
Joined: 15 Feb 2016 21:08

Writing unicode files

Post by MBaas »

I just noticed a problem when I tried to process that I exported from XY. For a repro, try this:

Code: Select all

    writefile("foo1.txt","""Mein Behälter"" C:\Data\Mein Behälter\",,"utf8bom");
Open foo1.txt with a binary editor and examine the two "ä"s: the first one is written as "C3 A4" - the second one as "61 CC 88".

I suppose this is "somewhat legal" - but it's not entirely correct:
VS Code (which is very tolerant) has no problems with it, UltraEdit can also handle it - but its hex mode shows there's some weirdness.
05-05-2024_15-02-01.png
And the environment I want to read it from simple injects blanks - which messes up subsequent processing, ofc.

Unfortunately I don't know this stuff well enough to provide a better explanation - but I hope it is reproduceable and fixable anyway ;)
To see the attached files, you need to log into the forum.
____________________________________________________________________________________
Happy user. Screen scaling 100% and W11Pro [Version 10.0.26200.7922], XY 28.30.14000 * * LinkTree

Horst
Posts: 1398
Joined: 24 Jan 2021 12:27
Location: Germany

Re: Writing unicode files

Post by Horst »

You write UTF 8 with BOM.
So get the BOM characters, or what else do you expect ?
Windows 11 Home, Version 25H2 (OS Build 26200.9168)
Portable x64 XYplorer (Actual version, including betas)
Display settings 1920 x 1080 Scale 100%
Everything 1.5.0.1422b (x64), Everything Toolbar 3.2, Listary Pro 7.0.0.9 beta

admin
Site Admin
Posts: 66541
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Writing unicode files

Post by admin »

Looks like a bug, but I ran your script and the resulting file looks as it should:
2024-05-05_164411.png
I'm using the English locale though, which might (but shouldn't!) make a difference:

Code: Select all

System / Thread Locale ID: 1033 (en-US) / 1033 (en-US)
Default ANSI Code Page: 1252  (ANSI - Latin I)
Active ANSI Code Page: 1252  (ANSI - Latin I)
Default OEM code page: 437   (OEM - United States)
Active OEM Code Page: 437   (OEM - United States)
To see the attached files, you need to log into the forum.

MBaas
Posts: 692
Joined: 15 Feb 2016 21:08

Re: Writing unicode files

Post by MBaas »

Just to confirm...I changed my system settings - but it did not affect the result of writefile!

My settings now match yours: (at least we know now that THIS did not cause the difference - as you said!)

Code: Select all

System / Thread Locale ID: 1033 (en-US) / 1033 (en-US)
Default ANSI Code Page: 1252  (ANSI - Latin I)
Active ANSI Code Page: 1252  (ANSI - Latin I)
Default OEM code page: 437   (OEM - United States)
Active OEM Code Page: 437   (OEM - United States)
____________________________________________________________________________________
Happy user. Screen scaling 100% and W11Pro [Version 10.0.26200.7922], XY 28.30.14000 * * LinkTree

admin
Site Admin
Posts: 66541
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Writing unicode files

Post by admin »

Try this:

Code: Select all

text utf8encode("""Mein Behälter"" C:\Data\Mein Behälter\", 1, 1);

MBaas
Posts: 692
Joined: 15 Feb 2016 21:08

Re: Writing unicode files

Post by MBaas »

Code: Select all

"Mein Behälter" C:\Data\Mein Behälter\
____________________________________________________________________________________
Happy user. Screen scaling 100% and W11Pro [Version 10.0.26200.7922], XY 28.30.14000 * * LinkTree

admin
Site Admin
Posts: 66541
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Writing unicode files

Post by admin »

And this:

Code: Select all

text hexdump(utf8encode("""Mein Behälter"" C:\Data\Mein Behälter\", 0, 1), 1);

MBaas
Posts: 692
Joined: 15 Feb 2016 21:08

Re: Writing unicode files

Post by MBaas »

Looks good as werll:

Code: Select all

00000000: 22 4D 65 69 6E 20 42 65 68 C3 A4 6C 74 65 72 22   "Mein Behälter"
00000010: 20 43 3A 5C 44 61 74 61 5C 4D 65 69 6E 20 42 65    C:\Data\Mein Be
00000020: 68 C3 A4 6C 74 65 72 5C                           hälter\        
____________________________________________________________________________________
Happy user. Screen scaling 100% and W11Pro [Version 10.0.26200.7922], XY 28.30.14000 * * LinkTree

admin
Site Admin
Posts: 66541
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Writing unicode files

Post by admin »

Hmm. Are you sure that UltraEdit is showing the truth?

MBaas
Posts: 692
Joined: 15 Feb 2016 21:08

Re: Writing unicode files

Post by MBaas »

It never lied to me (so far). i#ve attached the zipped file if you wanna check yourself.
To see the attached files, you need to log into the forum.
____________________________________________________________________________________
Happy user. Screen scaling 100% and W11Pro [Version 10.0.26200.7922], XY 28.30.14000 * * LinkTree

admin
Site Admin
Posts: 66541
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Writing unicode files

Post by admin »

Yes, it's true. Can't explain it. Seems impossible. :veryconfused:

What happens when you put more "ä" characters in the string? Any patterns?

MBaas
Posts: 692
Joined: 15 Feb 2016 21:08

Re: Writing unicode files

Post by MBaas »

It's weird! I tried to write lots of "ä"s - they all were correct. Just my real use case (with the folder name "Gehälter") and the random repro seem to expose that behavior...
____________________________________________________________________________________
Happy user. Screen scaling 100% and W11Pro [Version 10.0.26200.7922], XY 28.30.14000 * * LinkTree

admin
Site Admin
Posts: 66541
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Writing unicode files

Post by admin »

It might be a different "ä" pasted from somewhere. Try to delete this character and type it again.

MBaas
Posts: 692
Joined: 15 Feb 2016 21:08

Re: Writing unicode files

Post by MBaas »

Indeed - the folder name had "ä" in it (61 CC C9) which was faithfully reproduced when the file was created. It's many years old - I have no idea how it got in there. Possibly I used an inferior file mgr and for sure a different O/S. What a weird one - thanks for bearing with me and apologies for being so blind! :oops:
____________________________________________________________________________________
Happy user. Screen scaling 100% and W11Pro [Version 10.0.26200.7922], XY 28.30.14000 * * LinkTree

Post Reply