"Для разработчиков", "Серверные скрипты", "Описание функций", "Строки", "StringCharsCount".
Получить количество вхождений указанного символа в исходной строке.
function StringCharsCount(const s: string; ch: char): integer;
Параметр |
Тип |
Значение |
---|---|---|
s |
string |
исходная строка; |
ch |
char |
один символ. |
Количество вхождений указанного символа в строку. Если не будет ни одного вхождения либо строка пуста — функция вернёт 0.
const
LYRICS = 'I''m waking up to ash and dust'#13#10 +
'I wipe my brow and I sweat my rust'#13#10 +
'I''m breathing in the chemicals'#13#10 +
'I''m breaking in, shaping up, then checking out on the prison bus'#13#10 +
'This is it, the apocalypse'#13#10 +
'Whoa'#13#10 +
'I''m waking up, I feel it in my bones'#13#10 +
'Enough to make my systems blow'#13#10 +
'Welcome to the new age, to the new age'#13#10 +
'Welcome to the new age, to the new age';
var
sData, s: string;
iCount: integer;
begin
sData := LYRICS;
while length(sData) > 0 do begin
s := Fetch(sData, CRLF);
mLogScript(s, '"i" count = ' + IntToStr(StringCharsCount(LowerCase(s), 'i')));
end;
end.
[22:43:33] (Log "StringCharsCount"): ["i" count = 2] I'm waking up to ash and dust
[22:43:33] (Log "StringCharsCount"): ["i" count = 3] I wipe my brow and I sweat my rust
[22:43:33] (Log "StringCharsCount"): ["i" count = 4] I'm breathing in the chemicals
[22:43:33] (Log "StringCharsCount"): ["i" count = 6] I'm breaking in, shaping up, then checking out on the prison bus
[22:43:33] (Log "StringCharsCount"): ["i" count = 3] This is it, the apocalypse
[22:43:33] (Log "StringCharsCount"): ["i" count = 0] Whoa
[22:43:33] (Log "StringCharsCount"): ["i" count = 5] I'm waking up, I feel it in my bones
[22:43:33] (Log "StringCharsCount"): ["i" count = 0] Enough to make my systems blow
[22:43:33] (Log "StringCharsCount"): ["i" count = 0] Welcome to the new age, to the new age
[22:43:33] (Log "StringCharsCount"): ["i" count = 0] Welcome to the new age, to the new age
[22:43:33] (Run "StringCharsCount"): Время выполнения скрипта: 3 мс
[22:43:33] (Run "StringCharsCount"): Скрипт выполнен успешно.