text$ = "This is my sentence to change my words." PRINT text$ oldword$ = "my" newword$ = "your" x = Replace(text$, oldword$, newword$) IF x THEN PRINT text$; x END FUNCTION Replace (text$, old$, new$) 'can also be used as a SUB DO find = INSTR(start + 1, text$, old$) 'find location of a word in text IF find THEN count = count + 1 first$ = LEFT$(text$, find - 1) 'text before word including spaces last$ = RIGHT$(text$, LEN(text$) - (find + LEN(old$) - 1)) 'text after word text$ = first$ + new$ + last$ END IF start = find LOOP WHILE find Replace = count ' function returns the number of replaced words END FUNCTION |