[DUG] Get the number representation of WideChar?
Stefan Mueller
muellers at orcl-toolbox.com
Wed Oct 18 14:03:18 NZDT 2006
The easiest is to typecast a widechar as word:
c := mywidestring[5];
If word(c)>127 then
...
If you are going to work with a lot of Unicode text then I also suggest you
get one of those Unicode libraries (like
http://www.torry.net/vcl/vcltools/text/strconw.zip or the one that ships
with Jedi JCL).
Couple of important tips:
- Accessing a string as an array should work properly to return you a
widechar (c=mywidestring[4])
- the copy function also works normal with widestrings
- string concatenation only works if you typecast the first string as
widestring, otherwise it will convert the string to ansi (s :=
widestring('Hello ')+MyWideStrign)
Regards,
Stefan
-----Original Message-----
From: delphi-bounces at ns3.123.co.nz [mailto:delphi-bounces at ns3.123.co.nz] On
Behalf Of Todd Martin
Sent: Wednesday, October 18, 2006 6:48 AM
To: NZ Borland Developers Group - Delphi List
Subject: Re: [DUG] Get the number representation of WideChar?
Do you have the following MBCS functions in Delphi 5?
CharLen()
ByteType()
You should be able to use ord() for each byte in the character.
Todd.
----- Original Message -----
From: "Gajo Csaba" <csaba at enyem.com>
To: <delphi at ns3.123.co.nz>
Sent: Wednesday, October 18, 2006 1:21 AM
Subject: [DUG] Get the number representation of WideChar?
> Hello,
>
> I haven't been active on this list for several years, so I hope you're
> still alive :)
> I have a problem with Unicode characters. I'm doing a conversion from IDN
> to PunyCode. IDN is the domain name in any character set, for example in
> Arabic letters. This is converted to something like xn--fd4ewg.com
> (Punycode) so it is accessible eveywhere.
>
> I'm using Delphi 5. For Unicode characters I'm using the TNT component
> set.
>
> Now, to convert IDN strings to Punycode, I need to check each character.
> If Ord(ch) > 127 then it's a Unicode and I have to convert it.
> The problem is it looks like Ord doesn't support WideChar's. If I do Ord
> on any russian letter it will always work as if I've used Ord('?').
> Because of this, my conversion function always fails.
>
> Is there some way to get the number representation of a Unicode char?
>
> Also, I'm using AnsiPos for retrieving the starting position of
> substrings. Is there some similar method for Copy? For example, I'm not
> sure if Copy(str,1,1) will copy a wide character correctly, since
> WideChars are 2 bytes. I know that accessing wide chars with str[1] is
> wrong.
>
> Regards,
> Csaba
>
> _______________________________________________
> Delphi mailing list
> Delphi at ns3.123.co.nz
> http://ns3.123.co.nz/mailman/listinfo/delphi
>
>
>
>
> --
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.1.408 / Virus Database: 268.13.4/476 - Release Date: 14/10/2006
>
>
--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.408 / Virus Database: 268.13.4/476 - Release Date: 14/10/2006
_______________________________________________
Delphi mailing list
Delphi at ns3.123.co.nz
http://ns3.123.co.nz/mailman/listinfo/delphi
More information about the Delphi
mailing list