字符串查找替换

program recursion;

{$APPTYPE CONSOLE}
var
  sourcestr, searchstr, replacestr: string;
  i: Integer;

begin
  Write('源字符串:');
  Readln(sourcestr);
  Write('查找字符串:');
  Readln(searchstr);
  Write('替换字符串:');
  Readln(replacestr);
  {递归替换字符串中的字符}
  i := Pos(searchstr, sourcestr);
  while i <> 0 do
  begin
    Delete(sourcestr, i, Length(searchstr));
    Insert(replacestr, sourcestr, i);
    i := Pos(searchstr, sourcestr);
  end;

  Writeln(sourcestr);
  readln;
end.

效果如下:

5%@9P{TCG7)I810_4EX8}6R

看来还是得了解基本的东西,不然看啥都像天书…

posted @ 2017-03-08 21:48  陨落流星  阅读(452)  评论(0编辑  收藏  举报