본문 바로가기
Delphi Tip/문자

문자열에서 특정 단어가 몇번 들어갔는지 체크하는 함수

by MonoSoft 2021. 10. 11.
728x90
반응형

문자열에서 특정 단어가 몇번 들어갔는지 체크하는 함수

 

 

uses strutils;

 

function countword(const source, wordstr : string; index : integer = 1):integer;

var

 i, lensource : integer;
begin
 result := 0;
 lensource := length(source);
 i := index;                     // 일정 인덱스 이후의 문자를 검색.
 while i<=lensource do begin
   i := posex(wordstr,source,i);
   if i>0 then inc(result) else break;
   inc(i);
 end;
end;

 

 

728x90
반응형

'Delphi Tip > 문자' 카테고리의 다른 글

델파이 UTF-8  (0) 2023.11.15
Case문으로 문자 비교하기  (0) 2023.11.08
String 을 PAnsiChar 변환  (0) 2021.10.14
난수 문자열 만들기  (0) 2021.10.13
문자 사이에서 숫자 추출하기  (0) 2021.10.12

댓글