Le operazioni più comuni con i caratteri.
Program Prova_Caratteri; Var c1, c2: Char; Begin Write('Primo carattere '); Readln(c1); Write('Secondo carattere '); Readln(c2); Writeln; Writeln('Upcase(',c1, ') = ', Upcase(c1)); Writeln(' Ord(',c1, ') = ', Ord(c1) ); { Byte } Writeln(' Pred(',c1, ') = ', Pred(c1) ); Writeln(' Succ(',c1, ') = ', Succ(c1) ); Writeln('Upcase(',c2, ') = ', Upcase(c2)); Writeln(' Ord(',c2, ') = ', Ord(c2) ); { Byte } Writeln(' Pred(',c2, ') = ', Pred(c2) ); Writeln(' Succ(',c2, ') = ', Succ(c2) ); Writeln; Writeln(c1, ' < ', c2, ' = ', (c1 < c2)); { Boolean } Writeln(c1, ' <= ', c2, ' = ', (c1 <= c2)); Writeln(c1, ' = ', c2, ' = ', (c1 = c2)); Writeln(c1, ' > ', c2, ' = ', (c1 > c2)); Writeln(c1, ' >= ', c2, ' = ', (c1 >= c2)); Writeln(c1, ' <> ', c2, ' = ', (c1 <> c2)); Readln; End.
Note
- Gli operatori di confronto si basano sui codici ASCII…
- Un certo carattere può essere specificato in 3 modi diversi
- '...', un certo carattere della tastiera tra apici
- Chr(...), la funzione con un numero da 0 a 255 come argomento
- #..., il carattere # seguito da un numero da 0 a 255
- Anche la funzione Readkey restituisce un carattere.