2012-05: Text
Write a program to read in and spell-check a sentence of text from a user.
Hint: Use the Dictionary method as a spell checker to find any miss-spelt words and highlight these for the user.
Scrivi un programma che legge un testo inserito dall’utente e controlla se le parole sono scritte correttamente.
Suggerimento: utilizza l’oggetto Dictionary per individuare le parole senza definizione ed evidenziarle all’utente.
Soluzione
TextWindow.Write("Inserisci un testo in inglese: ")
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
risposta=Dictionary.GetDefinition(parola)
If Text.GetLength(risposta)=0 Then
TextWindow.BackgroundColor="blue"
TextWindow.Write(parola)
TextWindow.BackgroundColor="black"
Else
TextWindow.Write(parola)
EndIf
EndSub