Const
Str1: string = 'Mama mila ramu';
Str2: string = '_';
var
Str: string;
Function Replace(var S: string; s1, s2: string): byte;
{ Zamena pervogo vkhozhdeniya slova drugim slovom.
Replace(Stroka, Slovo, Na chto zamenit);
Rezultatom funktsii yavlyaetsya chislo - na kakoi
pozitsii v stroke bilo naideno slovo.
Vozvrashchaetsya 0, yesli slovo ne naideno. }
Begin
if ((length(S) + length(s2) - length(s1)) <= 255) and (pos(s1, S) <> 0) then
Begin
Replace := pos(S, s1);
S := copy(S, 1, pos(s1, S) - 1) + s2 + copy(S, pos(s1, S) + length(s1),
length(S));
End
else
Replace := 0;
End;
Begin
Str := Str1;
writeln('Gde zamenyaem: ', Str);
writeln('Na chto zamenyaem probeli: ', Str2);
while pos(' ', Str) <> 0 do
Replace(Str, ' ', Str2);
writeln('Chto poluchilos: ', Str);
End.