johnamanel Posted November 30, 2007 at 09:48 AM Report Share #151324 Posted November 30, 2007 at 09:48 AM Oi pessoal. Sou novo aqui como no Java..... Acreditem..... MMMMTTTT novo Gostava de saber como retirar os pontos finais, virgulas, pontos de exclamação e um texto etc.... Ou seja: public class split { public static void main (String[] args) { String s = "Para quem é novo no java, isto é muito dificil. A sério!!!"; String[] v; v = s.split(" "); for (int i=0; i<v.length; i++) System.out.println (v[i]); } } Acho que percebem que, quando uso o split, ele vai por no vector cada "palavra" numa posição. Só que mete também os "," e os "." e os "!!!". Por favor ajudem-me....... Link to comment Share on other sites More sharing options...
M6 Posted November 30, 2007 at 01:43 PM Report Share #151349 Posted November 30, 2007 at 01:43 PM Podes usar expressões regulares e fazes isso em 3 linhas de código. Deixo-te aqui uns links para te iniciares, aconselho-te a le-los todos: - http://java.sun.com/docs/books/tutorial/essential/regex/ - http://www.regular-expressions.info/java.html - https://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html 10 REM Generation 48K! 20 INPUT "URL:", A$ 30 IF A$(1 TO 4) = "HTTP" THEN PRINT "400 Bad Request": GOTO 50 40 PRINT "404 Not Found" 50 PRINT "./M6 @ Portugal a Programar." Link to comment Share on other sites More sharing options...
mobes Posted November 30, 2007 at 01:56 PM Report Share #151354 Posted November 30, 2007 at 01:56 PM Usar -> s.split("[ ,!.]"); 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