Sign in Join

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

Mailing lists / lazarus / 2009-11

UTF8 string compare

5 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

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

And3mD

How to compare utf8 strings

For example I have the sign "/" encoded as #47 and #192#175:

str1:=#47; // "/"
str2:=#192#175; // "/"

How to do:
if str1 = str2 then //not working CompareStr not working too. ....

Greetings
Andrzej And3mD Kilijanski

Reply by email

Vincent Snijders
to And3mD
And3mD wrote 7 lines
How to compare utf8 strings For example I have the sign "/" encoded as #47 and #192#175: str1:=#47; // "/" str2:=#192#175; // "/"

I don't think str2 is valid UTF8.

Vincent

Reply by email

Graeme Geldenhuys
to And3mD: How to compare utf8 strings For example I have the sign "/" encoded as #47 and #192#175:…
And3mD wrote
How to compare utf8 strings For example I have the sign "/" encoded as #47 and #192#175:

Those two are not the same character. Below I copied the "/" character Unicode information and other Unicode variants of that character. #192#175 does not seem to be any of those - I actually don't know what #192#175 is.

But to answer your question, you would probably have to normalize the strings and then do a Unicode compare. As far as I know this is not available in FPC.

You can download the utf8tools package which has many Unicode functions which will help you with what you need. See the following URL.

http://wiki.lazarus.freepascal.org/Theodp

-----------------------------------------------
U+002F SOLIDUS

General Character Properties

In Unicode since: 1.1
Unicode category: Punctuation, Other

Various Useful Representations

UTF-8: 0x2F
UTF-16: 0x002F

C octal escaped UTF-8: \057
XML decimal entity: /

Annotations and Cross References

Alias names:
? slash, virgule

See also:
? U+01C0 LATIN LETTER DENTAL CLICK
? U+0338 COMBINING LONG SOLIDUS OVERLAY
? U+2044 FRACTION SLASH
? U+2215 DIVISION SLASH
-----------------------------------------------

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/

Reply by email

Hans-Peter Diettrich
to And3mD: How to compare utf8 strings For example I have the sign "/" encoded as #47 and #192#175:…
Show quoted text 9 lines
How to compare utf8 strings For example I have the sign "/" encoded as #47 and #192#175: str1:=#47; // "/" str2:=#192#175; // "/" How to do: if str1 = str2 then //not working CompareStr not working too.

The strings obviously are different, not equal. If you want to compare the encoded *contents*, for equivalence, you'll have to use the appropriate function (dunno which one).

DoDi

Reply by email