简单,查找特定的字符串(在父串中),以及对字符串过滤,把想替换的字符替换掉

解决方案 »

  1.   

    用:
    function StringReplace(const S, OldPattern, NewPattern: string;
      Flags: TReplaceFlags): string;
      

  2.   

    //把所有的1替换成2
    var
      a:string;
    begin
      a:='11385312555';
      a:=StringReplace(a,'1','2',[rfReplaceAll]);
      showmessage(a);
    end;
      

  3.   

    又来晚了哈,给一个自己写的函数,里面有一个参数可以告诉你替代了几个
    function ReplaceAString(SourceStr,SourceSubStr,RelaceStr:string;var i_num:integer;):String;
    var
      ipos:integer;  
      Middle_str:String;
    begin
      i_num := 0;
      Middle_str := SourceStr;
      ipos:=pos(SourceSubStr,Middle_str);
      while (ipos > 0) do
        begin
          i_num := i_num + 1;
          Middle_str := copy(Middle_str,1,ipos-1)+RelaceStr+copy(Middle_str,ipos+length(SourceSubStr),length(Middle_str));
          ipos := pos(SourceSubStr,Middle_str);
        end;
      if i_num = 0 then
        Application.MessageBox('字符串中没有这个子串!','提示',mb_Ok)
      else
        result := middle_str;
    end;
      

  4.   

    pos('1','adsda1afa1a')
    返回第一次出现‘1’的位置
    你就可以判断如果大于零,就代表有拉
      

  5.   

    同意楼上的,用StrScan()也行。
      

  6.   

    function StringReplace(const S, OldPattern, NewPattern: string;
      Flags: TReplaceFlags): string;
      

  7.   

    function ReplaceAString(SourceStr,SourceSubStr,RelaceStr:string;var i_num:integer;):String;
    var
      ipos:integer;  
      Middle_str:String;
    begin
      i_num := 0;
      Middle_str := SourceStr;
      ipos:=pos(SourceSubStr,Middle_str);
      while (ipos > 0) do
        begin
          i_num := i_num + 1;
          Middle_str := copy(Middle_str,1,ipos-1)+RelaceStr+copy(Middle_str,ipos+length(SourceSubStr),length(Middle_str));
          ipos := pos(SourceSubStr,Middle_str);
        end;
      if i_num = 0 then
        Application.MessageBox('字符串中没有这个子串!','提示',mb_Ok)
      else
        result := middle_str;
    end;  
      

  8.   

    function StringReplace(const S, OldPattern, NewPattern: string; Flags: TReplaceFlags): string;