sabing Posted April 5, 2014 Report Share Posted April 5, 2014 Olá eu estou com dificuldade de verificar se tem numero antes de uma String Atributos c = new Atributos(); String regex = "1numero asdsadsad "; Pattern p = Pattern.compile(regex); Matcher m = p.matcher(c.data); while (m.find()) { System.out.println(m.group()); // tenho que mostrar so a string 1numero } Link to comment Share on other sites More sharing options...
KTachyon Posted April 5, 2014 Report Share Posted April 5, 2014 string.matches("^\\d.*"); “There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.” -- Tony Hoare Link to comment Share on other sites More sharing options...
sabing Posted April 5, 2014 Author Report Share Posted April 5, 2014 Beleza funcionou obrigado ! Link to comment Share on other sites More sharing options...
sabing Posted April 7, 2014 Author Report Share Posted April 7, 2014 Eu gostaria de identificar depois o numero Link to comment Share on other sites More sharing options...
daleixo Posted April 24, 2014 Report Share Posted April 24, 2014 Assim de repente, expressões regulares. Depois de identificado podes trabalhar com o substring. Link to comment Share on other sites More sharing options...
MaxUpGenGros Posted April 25, 2014 Report Share Posted April 25, 2014 A solução acho que é facil..depois de encontrares o numero podes guardá-lo numa variavel e fazer depois o Integer.valueOf() da tua string. FCoelho Link to comment Share on other sites More sharing options...
HappyHippyHippo Posted April 25, 2014 Report Share Posted April 25, 2014 import java.util.regex.Matcher; import java.util.regex.Pattern; public class main { static public void main(String[] args) { String c = "23twr"; String regex = "^\\d*"; Pattern p = Pattern.compile(regex); Matcher m = p.matcher(c); while (m.find()) { System.out.println(m.group()); } } } IRC : sim, é algo que ainda existe >> #p@p Portugol Plus Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now