Recent

Author Topic: [solved] utf8string, widestring and unicode  (Read 13509 times)

progamat

  • New Member
  • *
  • Posts: 32
[solved] utf8string, widestring and unicode
« on: November 05, 2010, 07:53:00 pm »
Hi,

I am trying to get the unicode of a char in a widestring or in a utf8string.

With Delphi, I wrote

Code: [Select]
vText : Widestring;
...
vCode := Integer(vText[i]);

to get the character code of ith character of the string

With Lazarus, if vText is a Widestring or a utf8string, vText is a ? (except with 'classical', so A-Z letters and the character code is wrong - yet right if A-Z).

What could be the best way to have the character code of the ith character ?

I searched hard, on this site and others places, before posting this topic.

I am surely stupid, perhpas the TUTF8Scanner would do what I want, but all my tries until now are unsuccessfull  :(
 
Tx a lot for any help
« Last Edit: November 08, 2010, 07:49:33 am by progamat »

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: utf8string, widestring and unicode
« Reply #1 on: November 05, 2010, 08:16:37 pm »
Try to do something like this:

Code: [Select]
uses LCLProc;

var
  p :PChar;
  unicode, charlen, n :integer;
  c :string;
begin
  p := PChar('ãâáàä');
  n := 1;
  repeat
    unicode := UTF8CharacterToUnicode(p, charlen);

    c := UTF8Copy(p, 1, 1);  // current character
    if c = 'ä' then ShowMessage(IntToStr(n));

    Inc(p, charlen);
    Inc(n);
  until (charlen = 0) or (unicode = 0);
end;                             
« Last Edit: November 05, 2010, 08:20:58 pm by typo »

progamat

  • New Member
  • *
  • Posts: 32
Re: utf8string, widestring and unicode
« Reply #2 on: November 05, 2010, 08:23:28 pm »
Tx a lot for your quick reply

What value has charlen, at first using of the parameter ?

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: utf8string, widestring and unicode
« Reply #3 on: November 05, 2010, 08:25:07 pm »
CharLen receives its value from the function UTF8CharacterToUnicode.

progamat

  • New Member
  • *
  • Posts: 32
Re: utf8string, widestring and unicode
« Reply #4 on: November 05, 2010, 08:33:37 pm »
Ok,

I just tried your code, and the compilator don't find the UTF8CharacterToUnicode

google says me that it's in the lclproc.pas ...

I surely have to add this file in my project ?

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: utf8string, widestring and unicode
« Reply #5 on: November 05, 2010, 08:35:04 pm »
Yes.

uses LCLProc;

progamat

  • New Member
  • *
  • Posts: 32
Re: utf8string, widestring and unicode
« Reply #6 on: November 05, 2010, 08:39:51 pm »
I just did it

Compilator now can't open the include file  "{$I fileutil.inc}  %)

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: utf8string, widestring and unicode
« Reply #7 on: November 05, 2010, 08:41:29 pm »
My Lazarus version:

Lazarus 0.9.29 r27895 FPC 2.4.3 i386-win32-win32/win64
« Last Edit: November 05, 2010, 08:45:01 pm by typo »

progamat

  • New Member
  • *
  • Posts: 32
Re: utf8string, widestring and unicode
« Reply #8 on: November 05, 2010, 08:44:30 pm »
I DLed today the 0.9.28.2 bbeta FPC 2.2.4 (the link at this page)

 

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: utf8string, widestring and unicode
« Reply #9 on: November 05, 2010, 08:46:00 pm »
I think this error is not inside that code.

progamat

  • New Member
  • *
  • Posts: 32
Re: utf8string, widestring and unicode
« Reply #10 on: November 05, 2010, 08:52:12 pm »
I still added fileutil.inc in the project, and path to it....but always same error msg  %)

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: utf8string, widestring and unicode
« Reply #11 on: November 05, 2010, 08:54:31 pm »
Quote
{$I fileutil.inc}

Where is that?

progamat

  • New Member
  • *
  • Posts: 32
Re: utf8string, widestring and unicode
« Reply #12 on: November 05, 2010, 09:00:48 pm »
this code is in the fileutil.pas

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: utf8string, widestring and unicode
« Reply #13 on: November 05, 2010, 09:02:19 pm »
Is FileUtil.pas in your uses clause?

progamat

  • New Member
  • *
  • Posts: 32
Re: utf8string, widestring and unicode
« Reply #14 on: November 05, 2010, 09:05:06 pm »
Not in my uses, but in the lclproc uses ....

I just tried, adding it in my uses, and this error is always here

 

TinyPortal © 2005-2018