想统计memo组件里面的某个单词的数量,例如,memo里面有多少个word这样的词语,
本人瞎写了一段,但没法实现。谢谢
var
      Tem1,Tem2:string;
     Tem_int,i,j:integer;  begin
           j:=0;
      tem1:=memo1.text;
      Tem2:=edit1.text;
      for i:=0   to  memo1.MaxLength   do
      begin
      Tem_int:=pos(Tem2,Tem1);
      j:=j+1;
      end;
     label1.caption:=inttostr(j);

解决方案 »

  1.   

    例如memo里面有以下内容,怎么可以统计出word有几个?谢谢wordabcwordabdwordw
    ordabcwordbbbwordbbb
      

  2.   

    用PosEx,否则Pos老是查询到第一个的。
      

  3.   

    有一个比较简单的方法,CSDN上原来有人用过,就是
    i:=Length(memo1.text)
    Memo1.Text:=StringReplace(Memo1.Text,Edit1.Text,[rfReplaceAll, rfIgnoreCase]);
    label1.caption:=(i-Length(Memo1.Text))/Length(Edit1.Text);
      

  4.   

    Memo1.Text:=StringReplace(Memo1.Text,Edit1.Text,'',[rfReplaceAll, rfIgnoreCase]);
      

  5.   

    const
      V = 'word';
    var
      I : integer;
      S : string;
    begin
      { 如果分布在两行上的单词也计算,就加这句,否则,就是:S := Memo1.Text }
      S := StringReplace(Memo1.Text,#13#10,'',[rfReplaceAll]);
      I := Length(S);
      S := StringReplace(S,V,'',[rfReplaceAll,rfIgnoreCase]);
      Showmessage(FloatToStr((I-Length(S)) / Length(V)));
    end;
      

  6.   

    忘记问了,各位大侠,要区分大小写字母的。dBASEIII(明年毕业了) 是正确的,应该怎样修改?