Fórum Como usar o String.matches() #568734
09/04/2009
0
Dragoncool
Curtir tópico
+ 0Posts
09/04/2009
Marcos Pereira
Gostei + 0
09/04/2009
Dragoncool
Gostei + 0
13/09/2011
Matheus Sproesser
Gostei + 0
13/09/2011
Douglas Eric
String arquivo = "nome_de_arquivo.tar.gz";
//para saber "se" tem um (ou mais) ponto(s) na String (true ou false)
System.out.println("contains: "+ arquivo.contains("."));
//para saber onde está o primeiro ponto*
System.out.println("indexOf: "+ arquivo.indexOf("."));
//para saber onde está o ultimo ponto*
System.out.println("lastIndexOf: "+ arquivo.lastIndexOf("."));
Gostei + 0
13/09/2011
Douglas Eric
Gostei + 0
13/09/2011
Douglas Eric
String texto;
if (texto.matches(".*\\..*")) {
...
}
String texto;
if (Pattern.compile("\\.").matcher(texto).find()) {
...
}
String texto;
Pattern pattern = Pattern.compile("\\.");
Matcher matcher = pattern.matcher(texto);
if (matcher.find()) {
...
}
String texto;
if (texto.contains(".")) {
...
}
String texto;
int index = texto.indexOf('.'); // ou .indexOf(".");
if (index != -1) {
// index é a posição do ponto
...
}
Gostei + 0
13/09/2011
Douglas Eric
Gostei + 0
27/11/2013
Douglas Eric
String string1 = "//";
String string2 = "// Isso é apenas um teste";
String regex = "^\/\/";
if (string1.matches(regex) && string2.matches(regex)) {
System.out.println("Achou");
}
Gostei + 0