Schuenemann 5 de abr. de 2011
Metaleiro 5 de abr. de 2011
[color=darkblue]Obrigado pela ajuda, depois descobri que o que eu precisava era apenas contar 3 letras em uma String e validar, vou deixar aqui as duas soluções, obrigado: [/color]
import javax.swing.JOptionPane ;
public class TesteExpressao {
/**
* @param args
*/
public static void main ( String [] args ) {
// TODO Auto-generated method stub
String teste1 = "AAA11" ;
String teste2 = "B2B1B" ;
String teste3 = "B8B888B88" ;
boolean sohLetrasEEspacos = teste1 . matches ( "[a-zA-Z]{3}\d+" );
System . out . println ( "Teste1 = " + sohLetrasEEspacos );
sohLetrasEEspacos = teste2 . matches ( "[a-zA-Z]{3}\d+" );
System . out . println ( "Teste2 = " + sohLetrasEEspacos );
sohLetrasEEspacos = teste3 . matches ( "[a-zA-Z]{3}\d+" );
System . out . println ( "Teste3 = " + sohLetrasEEspacos );
String temp = "" ;
boolean teste ;
int count = 0 ;
for ( int i = 0 ; i < teste3 . length (); i ++ ){
char ch = teste3 . charAt ( i );
temp = Character . toString ( ch );
teste = temp . matches ( "[a-zA-Z]" );
if ( teste ){
count ++ ;
}
}
if ( count > 3 ){
JOptionPane . showMessageDialog ( null , "FUNFOOOOOOOOOOOOOU !" );
}
}
}
Schuenemann 5 de abr. de 2011
boolean sohLetrasEEspacos = teste1 . matches ( "[a-zA-Z]{3}\d+" );
Isso só testa se em algum ponto da string tem isso.
“3aaa %e” passa nesse seu teste .
E no for use Character.isLetter() e demais métodos dessa classe.
Metaleiro 5 de abr. de 2011
:arrow:
Schuenemann:
boolean sohLetrasEEspacos = teste1.matches("[a-zA-Z]{3}\d+");
Isso só testa se em algum ponto da string tem isso.
“3aaa %e” passa nesse seu teste .
E no for use Character.isLetter() e demais métodos dessa classe.
[color=darkblue] Funcionou legal, obrigado[/color]
int count = 0 ;
for ( int i = 0 ;i<teste3.length();i++){
char ch = teste3 .charAt ( i ) ;
if ( Character .isLetter ( ch )) {
count ++ ;
}
}
if ( count > 3 ) {
JOptionPane .showMessageDialog ( null , "FUNFOOOOOOOOOOOOOU !" ) ;
}