That is very strange. The lastIndexOf('.') routine should return the string position of the last "." in the string.
Quote:
|
The **lastIndexOf()** method in Java's String class is used to find the index of the last (rightmost) occurrence of a specified character or substring within a given string. The search starts from the end of the string and proceeds backward, but the returned index is still zero-based from the beginning of the string.
|
So if "demo 1.4.odt" is passed in the getFileExtension routine should return the substring ".odt" and the removeExtension routine should return the original string short the last 4 ".odt" characters. which should be what you want.
How on earth does the lastIndexOf('.') find and return the first '.'?
Great detective work! But something else may be up. It is as-if like they ran it through that routine twice or in a loop and so it first hacked off the ".odt" and then hacked off the ".4" as using this routine just once should do exactly what you would want.
Perhaps they invoke that string in a loop? Or maybe that there are multiple threads that somehow invoke it twice?