1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
public static void main(String[] args)
{
System.out.println(getLastCharBeforeDot("nom_du_fichier_ddddeeef.xml"));
}
public static String getLastCharBeforeDot(String fileName)
{
String buffer =""; //initialise la variable
String name = fileName.substring(0, fileName.lastIndexOf(".")); //Je récupère le string entre la position 0 et jusqu'au dernier point de la chaine
int index = name.length() - 4; //Je choisis ou je me place, en occurrence je prends la taille de la chaine et je lui enleve 4 (tu peux mettre 5 si tu veux les 5 dernières)
for(int i = index; i < name.length(); i++)
{
buffer += name.charAt(i); // j'ajoute chaque lettre rencontrée
}
return buffer;
} |
Partager