Sounds more like a beginner's question. You can parse the String with the methods of the String class and find the index of the "." and then get a substring. [ July 23, 2008: Message edited by: Campbell Ritchie ]
Joined: Jan 11, 2008
Hi, I tried using substring.but I got some problem in that. Please give the solution. I put my code here.
If i use the like above(ie.I pass the value directly)i got exact filename get_url.but i can't use like this.When I click the browse button I take any file and its path may be different. I definitely use like follows. But that time I can't get exact filename.
If i use the like above I got filename D:\MDM\get_url.please give the solution.
Check for file path seperator. In your case, it seems to be the '\' and not the '/' which you are checking. 1. Check what the file path seperator is and store it in a variable. 2. Use this variable to get to the last occurence of the seperator.
Life called,so here I am.<br />Cheers<br />Niki.:-)
Niki Nono was nearly correct; you look for the path separator and file separator. But you don't have to search far for them; there are fields in the File class called separator or pathSeparator which encapsulate that information, so you can find the last index of those characters. You can also find them from the System class. Look through the File class and see which you need; I think it's "separator," not "path separator." No need to hard-code "\\" or "/" which would limit portability.
. . . myURL.substring(myURL.lastIndexOf(File.separator) + 1, myURL.lastIndexOf(".")); or something similar.
Joined: Oct 13, 2005
My technique will not cause problems if you pass a String like "myFile.txt" without / or \\ but you will get problems if there is no "." in it anywhere. That might require two substring calls.