Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2016-10

Windows and german Umlauts: why do i have to PWideChar(UTF8Decode(String)) and not UTF8ToAnsi(String)

7 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Landmesser John

I know how to deal with german Umlauts but I would like to understand.

Think of a *.csv file that contains strings like "Grünberg" and that has to be opened in Excel ( Office 2003 ).

It works if i use PWideChar(UTF8Decode(String)). Got this tipp here in the mailinglist!

But UTF8ToAnsi(String) fails.

Why is UTF8ToAnsi(String) not enough?

LHelp tells me about UTF8ToAnsi():
"Utf8ToAnsi converts an utf8-encode unicode string to an ansistring. It converts the string to a widestring and then converts the widestring to an ansistring."

That is NOT the same as PWideChar(UTF8Decode(String))?

Tipps are welcome.

Thank you!!

Reply by email

Mattias Gaertner
to Landmesser John
Show quoted text 18 lines
I know how to deal with german Umlauts but I would like to understand. Think of a *.csv file that contains strings like "Grünberg" and that has to be opened in Excel ( Office 2003 ). It works if i use PWideChar(UTF8Decode(String)). Got this tipp here in the mailinglist! But UTF8ToAnsi(String) fails. Why is UTF8ToAnsi(String) not enough? LHelp tells me about UTF8ToAnsi(): "Utf8ToAnsi converts an utf8-encode unicode string to an ansistring. It converts the string to a widestring and then converts the widestring to an ansistring." That is NOT the same as PWideChar(UTF8Decode(String))?

Obviously, because one produces an 8-bit string and the other a 16-bit string. How do you compare the result?

What compiler version?
Are you using LazUTF8? What is your DefaultSystemCodePage?

Mattias

Reply by email

Landmesser John
to Mattias Gaertner
Mattias Gaertner wrote
That is NOT the same as PWideChar(UTF8Decode(String))? Obviously, because one produces an 8-bit string and the other a 16-bit string. How do you compare the result?

I compare the results by open the *.csv file in Excel 2003 and see no correct "Grünberg"
Note: my Editor "TextPad" shows "PC UTF8" as file encoding if i use UTF8ToAnsi.

What compiler version?

Sorry, forgot that:

Lazarus 1.7 latest trunk FPC 3.0.0 i386-win32-win32/win64

Windows XP

Are you using LazUTF8?

Where to look for that?
"Alle Dateien haben bereits die richtige Kodierung" -> UTF8

What is your DefaultSystemCodePage? Mattias

in Systemsettings language its: "Automatisch ( oder Englisch)"

So the answer seems to be:
"one produces an 8-bit string and the other a 16-bit "

Reply by email

Mattias Gaertner
to Landmesser John
Show quoted text 9 lines
Am 18.10.2016 um 09:36 schrieb Mattias Gaertner via Lazarus: > That is NOT the same as PWideChar(UTF8Decode(String))? > Obviously, because one produces an 8-bit string and the other a 16-bit > string. How do you compare the result? I compare the results by open the *.csv file in Excel 2003 and see no correct "Grünberg" Note: my Editor "TextPad" shows "PC UTF8" as file encoding if i use UTF8ToAnsi.

Did you start the csv file with the UTF8 BOM, so that Excel knows that the file is UTF-8 encoded?

UTF8BOM = #$EF#$BB#$BF

Show quoted text 11 lines
> What compiler version? Sorry, forgot that: Lazarus 1.7 latest trunk FPC 3.0.0 i386-win32-win32/win64 Windows XP > Are you using LazUTF8? Where to look for that?

LazUTF8 is a unit, that sets the global variable
DefaultSystemCodePage to CP_UTF8. DefaultSystemCodePage defines the default encoding of AnsiString, so UTF8ToAnsi creates UTF-8. LazUTF8 is used by LCL applications.
If unsure use writeln or use the debugger to find out the value of DefaultSystemCodePage.

Show quoted text 11 lines
"Alle Dateien haben bereits die richtige Kodierung" -> UTF8 > What is your DefaultSystemCodePage? > > Mattias in Systemsettings language its: "Automatisch ( oder Englisch)" So the answer seems to be: "one produces an 8-bit string and the other a 16-bit "

And PWideChar is a pointer, while UT8ToAnsi creates a String.

Mattias

Reply by email

Jürgen Hestermann
to Mattias Gaertner
Mattias Gaertner wrote
Did you start the csv file with the UTF8 BOM, so that Excel knows that the file is UTF-8 encoded? UTF8BOM = #$EF#$BB#$BF

In

https://en.wikipedia.org/wiki/Comma-separated_values

it says:

"Also, many regional versions of Excel will not be able to deal with Unicode in CSV."

and

"One simple solution when encountering such difficulties is to change the filename extension from .csv to .txt; then opening the file from an already running Excel instance with the "Open" command, where the user can manually specify the delimiters, encoding, format of columns, etc."

Reply by email