Récuperation d'une chaine dans un string JAVA
Résolu/Fermé
dickon
-
4 mai 2008 à 11:53
vignemail1 Messages postés 1246 Date d'inscription vendredi 8 octobre 2004 Statut Contributeur Dernière intervention 13 septembre 2019 - 4 mai 2008 à 15:03
vignemail1 Messages postés 1246 Date d'inscription vendredi 8 octobre 2004 Statut Contributeur Dernière intervention 13 septembre 2019 - 4 mai 2008 à 15:03
A voir également:
- Récuperation d'une chaine dans un string JAVA
- Waptrick java football - Télécharger - Jeux vidéo
- Jeux java itel football - Télécharger - Jeux vidéo
- Chaine tnt gratuite sur mobile - Guide
- Java apk - Télécharger - Langages
- Waptrick java voiture - Télécharger - Jeux vidéo
5 réponses
vignemail1
Messages postés
1246
Date d'inscription
vendredi 8 octobre 2004
Statut
Contributeur
Dernière intervention
13 septembre 2019
259
4 mai 2008 à 12:06
4 mai 2008 à 12:06
String url="lol/mdr:"; String lol_recup=url.substring(0,url.indexOf("/")); out.println(lol_recup); String mdr_recup = url.substring(url.indexOf("/")+1, url.indexOf(":")); out.println(mdr_recup);
dickon
Messages postés
7
Date d'inscription
dimanche 4 mai 2008
Statut
Membre
Dernière intervention
13 mai 2008
4 mai 2008 à 12:10
4 mai 2008 à 12:10
Merci ^^
vignemail1
Messages postés
1246
Date d'inscription
vendredi 8 octobre 2004
Statut
Contributeur
Dernière intervention
13 septembre 2019
259
4 mai 2008 à 12:29
4 mai 2008 à 12:29
Sinon tu peux passer par des StringTokenizer ou même des Regex
dickon
Messages postés
7
Date d'inscription
dimanche 4 mai 2008
Statut
Membre
Dernière intervention
13 mai 2008
4 mai 2008 à 12:51
4 mai 2008 à 12:51
Ca marche comment?
t'as un exemple?
t'as un exemple?
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question
vignemail1
Messages postés
1246
Date d'inscription
vendredi 8 octobre 2004
Statut
Contributeur
Dernière intervention
13 septembre 2019
259
4 mai 2008 à 15:03
4 mai 2008 à 15:03
Regarde la doc de la JDK:
cela donne :
mais tu peux aussi spécifier les délimiteurs dans le constructeur du StringTokenizer :
public StringTokenizer(String str, String delim)
Constructs a string tokenizer for the specified string. The characters in the delim argument are the delimiters for separating tokens. Delimiter characters themselves will not be treated as tokens.
Note that if delim is null, this constructor does not throw an exception. However, trying to invoke other methods on the resulting StringTokenizer may result in a NullPointerException.
Parameters:
str - a string to be parsed.
delim - the delimiters.
Throws:
NullPointerException - if str is null
Il y a aussi un truc similaire dans la classe String : la méthode split()
Pour les Regex, regarde la doc pour la classe Pattern
StringTokenizer st = new StringTokenizer("this is a test"); while (st.hasMoreTokens()) { System.out.println(st.nextToken()); }
cela donne :
this is a test
mais tu peux aussi spécifier les délimiteurs dans le constructeur du StringTokenizer :
public StringTokenizer(String str, String delim)
Constructs a string tokenizer for the specified string. The characters in the delim argument are the delimiters for separating tokens. Delimiter characters themselves will not be treated as tokens.
Note that if delim is null, this constructor does not throw an exception. However, trying to invoke other methods on the resulting StringTokenizer may result in a NullPointerException.
Parameters:
str - a string to be parsed.
delim - the delimiters.
Throws:
NullPointerException - if str is null
Il y a aussi un truc similaire dans la classe String : la méthode split()
Pour les Regex, regarde la doc pour la classe Pattern