function JumlahKata(S: string): integer;
const
SPASI_GANDA = ' ';
SPASI = ' ';
//Anda bisa tambahkan simbol lainnya
Simbol = '():;[]{}"''`!,?.';
var
i: byte;
begin
if S='' then
Result := 0
else
begin
//Ubah simbol2x menjadi spasi
for i:=1 to Length(Simbol) do
S := StringReplace(S, Simbol[i], SPASI, [rfReplaceAll]);
//Hapus spasi ganda
while Pos(SPASI_GANDA, S)>0 do
S := StringReplace(S, SPASI_GANDA, SPASI, [rfReplaceAll]);
//Hapus spasi di awal kalimat
if S[1]=SPASI then Delete(S, 1, 1);
//Hapus spasi di akhir kalimat
if S[Length(S)]=SPASI then Delete(S, Length(S), 1);
Result := 1;
while Pos(SPASI, S)>0 do begin
Delete(S, 1, Pos(SPASI,S));
Inc(Result);
end;
end;
end;
Wednesday, April 25, 2007
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment