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.
效果如下:
看来还是得了解基本的东西,不然看啥都像天书…