D
D
Dmitry2021-11-18 16:53:21
Delphi
Dmitry, 2021-11-18 16:53:21

How to find Russian letters in Memo on Delphi XE2?

The task is to count how many letters are in the text. This text is in Memo. There are no problems with searching and counting English letters. But the problem is with the Russians.
Tried it like this:

bukv = [(#65)..(#90),(#97)..(#122),(#192)..(#255)];

so:
bukv = [(#65)..(#90),(#97)..(#122),'а'..'я','А'..'Я','ё','Ё'];

so:
bukv = [(#65)..(#90),(#97)..(#122),'а'..'п', 'р'..'я', 'ё'];

and I even decided to try this:
bukv = [(#65)..(#90),(#97)..(#122),AnsiCHar(#192)..AnsiCHar(#255)];

and for a snack:
bukv = [(#65)..(#90),(#97)..(#122),AnsiCHar('А')..AnsiCHar('я')];


None of the above examples work in Delphi XE2. Help me please!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
H
Hemul GM, 2021-11-28
@demiancz

[ ] is a set. It is limited in number and type of data.
Only 255 values ​​and only byte.
In Memo, you write the text already in Unicode, which means that Russian characters there are not included in the range 0..255, they have completely different meanings.
Therefore, there is no need to use a set.
Add a function to check if a character is Russian or not

var Cyrillics: string := 'абвгдеёжзийклмнопрстуфхцчшщъыьэюя';
...
function IsCyrillic(const Ch: Char): Boolean;
begin
  for var C in Cyrillics do
    if C.ToLower = Ch then Exit(True);
  Result := False;
end;
...
function CyrillicCount(const Text: string): Cardinal;
begin
  Result := 0;
  for var C in Text do
    if IsCyrillic(C) then Inc(Result);
end;
...
var Count := CyrillicCount(Memo.Text);

K
kalapanga, 2021-11-18
@kalapanga

Letters set like this
bukv = 'abvgd';
Check like this
if Pos(Memo1.Lines[i][j], bukv)>0 then ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question