Week 4: Text 1
Write a program to replace all occurrences of the word red with blue in the following sentence:
The red car was going incredibly fast when it passed the red stop sign, before reducing its speed and hitting a lorry carrying red paint.
Scrivi un programma per rimpiazzare tutte le occorrenze della parola red con la parola blue
Soluzione
testo="The red car was going incredibly fast when it passed the red stop sign, before reducing its speed and hitting a lorry carrying red paint." TextWindow.WriteLine(testo) posizione=1 While posizione <> 0 posizione=Text.GetIndexOf(testo, " red ") if posizione <> 0 Then prima = Text.GetSubText(testo, 1, posizione-1) dopo = Text.GetSubTextToEnd(testo, posizione+5) testo = Text.Append(prima, " blue ") testo = Text.Append(testo, dopo) EndIf ' TextWindow.WriteLine(testo) EndWhile TextWindow.WriteLine(testo)