Week 7: Text 2
Write a program that will reverse each individual word in a sentence but leave the order of words unchanged.
Example
INPUT: Hasta la vista
OUTPUT: atsaH al atsiv
Scrivi un programma che capovolge le singole parole in una frase, lasciando inalterato l’ordine delle parole.
Soluzione
TextWindow.Write("Inserisci un testo: ")
testo=TextWindow.Read()
'------------------------------------------------------------
'------------------------------------------------------------
ELENCO="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
IN_PAROLA=0
parola=""
For i=1 To Text.GetLength(testo)
car=Text.GetSubText(testo,i,1)
If Text.IsSubText(ELENCO,car) Then
IN_PAROLA=1
parola=parola+car
Else
If IN_PAROLA=1 Then
IN_PAROLA=0
GestisciParola()
parola=""
EndIf
TextWindow.Write(car)
EndIf
EndFor
'------------------------------------------------------------
If IN_PAROLA=1 Then
GestisciParola()
EndIf
'------------------------------------------------------------
TextWindow.WriteLine("")
'------------------------------------------------------------
'------------------------------------------------------------
Sub GestisciParola
parolaOutput=""
For j=Text.GetLength(parola) To 1 Step -1
parolaOutput=Text.Append(parolaOutput, Text.GetSubText(parola, j, 1))
EndFor
TextWindow.Write(parolaOutput)
EndSub