|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Jun 2009
Messaggi: 5626
|
Java - vincolo stringa
Come si può impostare il fatto che siano accettate solo stringhe del tipo {stringa}?
Grazie in anticipo |
|
|
|
|
|
#2 | |
|
Senior Member
Iscritto dal: Oct 2008
Messaggi: 359
|
Quote:
Codice:
String test = "{stringa}";
if (test.length() > 1 && test.charAt(0) == '{' && test.charAt(test.length() -1) == '}')
System.out.println("valida");
else
System.out.println("non valida");
|
|
|
|
|
|
|
#3 |
|
Senior Member
Iscritto dal: Jun 2009
Messaggi: 5626
|
grazie,
se invece deve essere nella forma "not stringa"? |
|
|
|
|
|
#4 |
|
Senior Member
Iscritto dal: Oct 2008
Messaggi: 359
|
Sempre nell'ipotesi che questa volta NON siano valide le stringhe che iniziano per graffa aperta e finiscono per graffa chiusa, allora ti basta invertire l'if:
Codice:
String test = "{stringa}";
if (test.length() > 1 && test.charAt(0) == '{' && test.charAt(test.length() -1) == '}')
System.out.println("non valida");
else
System.out.println("valida");
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 09:51.




















