Oppure

Loading
13/09/08 15:39
Mak
Ciao a tutti.
Volevo chiedere se si può fare in modo che un programma, con una variabile string, non riconosca la differenza tra le lettere maiuscole e minuscole? Non so se mi sono spiegato bene...
Ultima modifica effettuata da pierotofy 13/09/08 18:10
aaa
13/09/08 18:15
pierotofy
Certo che si può. Trasforma le due stringhe che devi confrontare tutte in maiuscolo o minuscolo (vedi sotto) e poi confrontale.

{ convert lower case letters to upper case }
For Location := 1 to Length(St) Do
  St[Location] := UPCASE(St[Location]);

{ convert upper case letters to lower case }
Valid_Ch := ['A'..'Z'];
For Location := 1 to Length(St) Do
  If St[Location] IN Valid_Ch
    Then St[Location] := CHR(ORD(St[Location]) + 32);
Il mio blog: piero.dev
17/09/08 13:39
Mak
Grazie per la risposta, anche se non ho molto capito...
Quindi, se io ho questo codice (preso da questo sito):
 Program password;
Uses Crt;
Var parola:string[40];
begin
    clrscr;
    writeln(‘Immettere la password: ‘);
    readln(parola);
    if parola=’Pascal’ Then 
      writeln(‘Bravo!’)
    else                    
      begin
      TextColor(5);
      TextBackGround(15);
      writeln(‘Sbagliato!’);
      end;
    readln
end.

come uso il codice? Grazie
aaa
17/09/08 13:48
Anonymous
in teoria dovrebbe venir cosi

prova un pò


program password;
uses Crt;
var st:string[40]; location:integer;
begin
    clrscr;
    writeln(‘Immettere la password: ‘);
    readln(st);
{ convert lower case letters to upper case }
for Location := 1 to Length(St) do
  St[Location] := UPCASE(St[Location]);

{ convert upper case letters to lower case }
for Location := 1 to Length(St) do
  if St[Location] in['A'..'Z']
    then St[Location] := CHR(ORD(St[Location]) + 32); 
    if st=’pascal’ then
      writeln(‘Bravo!’)
    else                    
      begin
      TextColor(5);
      TextBackGround(15);
      writeln(‘Sbagliato!’);
      end;
    readln
end.


Ultima modifica effettuata da Anonymous 17/09/08 13:55
aaa
17/09/08 16:49
Mak
Perfetto :k:
un'ultima cosa, le frasi tra parentesi graffe sono commenti? Sarebbe come scrivere (* *)?
aaa
17/09/08 17:06
Anonymous
sisi.. sono commenti
aaa