Bonjour,
Je veux bien créer une fonction qui coupe toutes les espaces avant et après un String, voici mon code:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
public class TextProcess {
public static String RemoveSpace(String text){
	return RemoveSpaceAfter(RemoveSpaceBefore(text));
}

public static String RemoveSpaceAfter(String text){
	while(text.endsWith(" ")){
		 return RemoveSpaceAfter(text.substring(0, text.length()-2));
	}
	return text;
}

public static String RemoveSpaceBefore(String text){
	if(text.startsWith(" ")){
		 return RemoveSpaceBefore(text.substring(1, text.length()-1));
	}
	return text;
}	
}
Le résultat est faux,, il me faut donc changer le code en:


Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
public static String RemoveSpaceAfter(String text){
	while(text.endsWith(" ")){
		 return RemoveSpaceAfter(text.substring(0, text.length()-1));
	}
	return text;
}
C'est très bizarre parce que text.substring(0, text.length()-1) c'est exactement text