Possible Duplicate:
How do I split a string with any whitespace chars as delimiters?
I want to break up a string in java. I have a string "message.txt.cpabe".I want to remove the last portion and only want "message.txt". How do I do it?
Possible Duplicate:
How do I split a string with any whitespace chars as delimiters?
I want to break up a string in java. I have a string "message.txt.cpabe".I want to remove the last portion and only want "message.txt". How do I do it?
String s = "message.txt.cpabe";
int indexOfLast = s.lastIndexOf(".");
String newString = s;
if(indexOfLast >= 0) newString = s.substring(0, indexOfLast);
System.out.println(newString); // prints "message.txt"
I would use LastIndexOf(".") to get the index of that last '.', and then use substring() to cut out the part that you want.
String str="message.txt.cpabe";
str=str.substring(0,str.lastIndexOf("."));
Try this.
Probably not what you wanted but certainly what you asked for.. :-)
String original = "message.txt.cpabe";
original = "message.txt";