[DUG] Upgrading to XE - Unicode strings questions

Colin Johnsun colin.adug at gmail.com
Tue Nov 23 14:31:02 NZDT 2010


I won't answer everything but just on this one question:

On 23 November 2010 11:04, John Bird <johnkbird at paradise.net.nz> wrote:

> Extra question:
>
> It looks like code like
>
>    for i:=1 to length(string1) do
>    begin
>            DoSomethingWithOneChar(string1[i]);
>    end;
>
> cannot be used reliably.   The problems are that length(string1) looks like
> it cannot be safely used - as unicode characters may include 2 codepoints
> and length(string1) highlights that there is a difference between the
> number
> of unicode characters in a string and the number of codepoints.   Still
> figuring out what is the best practice here, as I have quite a lot of
> string
> routines.   Should be be OK as long as the unicode text actually is ASCII.
>
>
you can use something like this:

var
  C: Char;
...
  for C in String1 do
  begin
    DoSomethingWithOneChar(C);
  end;

In this case you don't need to know the index of each character, you just
get the char using the for..in..do loop.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://listserver.123.net.nz/pipermail/delphi/attachments/20101123/12e97ae2/attachment.html 


More information about the Delphi mailing list