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

Mailing lists / lazarus / 2009-11
5 messages · 4 people · –
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
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
I don't think str2 is valid UTF8.
Vincent
It is a so-called overlong form:
See: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 http://en.wikipedia.org/wiki/UTF-8#Invalid_byte_sequences
Vincent
How to compare utf8 strings For example I have the sign "/" encoded as #47 and #192#175:…
And3mD wroteHow 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 -
How to compare utf8 strings For example I have the sign "/" encoded as #47 and #192#175:…
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