def var sent as char no-undo.
sent = "Today I will go to Tony's Pizza-Ria to get some tomato pie. Plus, Its best to get top server for tomorrow's toga party. No lets go to the marker and get some Tostitos".
run replaceWords(input-output sent,"to", "FOOBAR").
message sent view-as alert-box.
procedure replaceWords:
def input-output param vstr as char no-undo. /* string */
def input param oword as char no-undo. /* OLD WORD*/
def input param nword as char no-undo. /* NEW WORD */
def var x as int no-undo. /* COUNTER */
do x = 1 to length(vstr):
if substr(vstr, x, (length(oword) + 2)) = " " + oword + " " then
vstr = replace(vstr, substr(vstr, x,length(oword) + 2), " " + nword + " ").
else if substr(vstr, x, (length(oword) + 2)) = " " + oword + "." then
vstr = replace(vstr, substr(vstr, x,length(oword) + 2), " " + nword + ".").
else if substr(vstr, x, (length(oword) + 2)) = " " + oword + "!" then
vstr = replace(vstr, substr(vstr, x,length(oword) + 2), " " + nword + "!").
else if substr(vstr, x, (length(oword) + 2)) = " " + oword + ":" then
vstr = replace(vstr, substr(vstr, x,length(oword) + 2), " " + nword + ":").
else if substr(vstr, x, (length(oword) + 2)) = " " + oword + "?" then
vstr = replace(vstr, substr(vstr, x,length(oword) + 2), " " + nword + "?").
else if substr(vstr, x, (length(oword) + 2)) = " " + oword + "(" then
vstr = replace(vstr, substr(vstr, x,length(oword) + 2), " " + nword + "(").
else if substr(vstr, x, (length(oword) + 2)) = " " + oword + "/" then
vstr = replace(vstr, substr(vstr, x,length(oword) + 2), " " + nword + "/").
else if substr(vstr, x, (length(oword) + 2)) = " " + oword + ";" then
vstr = replace(vstr, substr(vstr, x,length(oword) + 2), " " + nword + ";").
else if substr(vstr, x, (length(oword) + 2)) = " " + oword + "+" then
vstr = replace(vstr, substr(vstr, x,length(oword) + 2), " " + nword + "+").
else if substr(vstr, x, (length(oword) + 2)) = " " + oword + "-" then
vstr = replace(vstr, substr(vstr, x,length(oword) + 2), " " + nword + "-").
else if substr(vstr, x, (length(oword) + 2)) = " " + oword + "*" then
vstr = replace(vstr, substr(vstr, x,length(oword) + 2), " " + nword + "*").
else if substr(vstr, x, (length(oword) + 2)) = " " + oword + "=" then
vstr = replace(vstr, substr(vstr, x,length(oword) + 2), " " + nword + "=").
end.
end.