Forum > General
how to return ascii code for char?
(1/1)
jw:
I would like to know how to return ascii code for characters in a string. The ord function should work but I'm getting
error: incompatible types: got "ansistring" expected char
code
stringy:='abcdefg';
for a:=1 to length(stringy) do
begin
edit2.text:=edit2.text + inttostr(ord(Copy(stringy,a,1)));
end;
I cant find a string manipulation command that returns a char to use in place of copy.
Martin_fr:
ord(stringy[a])
However this returns the byte (not char) at the given position. But copy does the same, copy accesses the string by bytes.
so as soon as any accented, umlaut, or other such char occurs in you string, that will break. Because by default Lazarus uses UTF8, and chars can use between 1 and 4 bytes.
Then again for UTF8 chars there is no ascii-code (and no function like ord).
in LCLProc there are a few string handling functions like UTF8Length.
jw:
the stringy[a] was what I couldn't fugure out access the stringy like an array thanks!
Navigation
[0] Message Index