Answer the question
In order to leave comments, you need to log in
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)];
bukv = [(#65)..(#90),(#97)..(#122),'а'..'я','А'..'Я','ё','Ё'];
bukv = [(#65)..(#90),(#97)..(#122),'а'..'п', 'р'..'я', 'ё'];
bukv = [(#65)..(#90),(#97)..(#122),AnsiCHar(#192)..AnsiCHar(#255)];
bukv = [(#65)..(#90),(#97)..(#122),AnsiCHar('А')..AnsiCHar('я')];
Answer the question
In order to leave comments, you need to log in
[ ] 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);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question