Results 1 to 7 of 7
- 05-29-2011, 08:36 PM #1
Member
- Join Date
- Nov 2010
- Posts
- 24
- Rep Power
- 0
How to withdraw a specific from a String?
Hi, i have a "windows URL" and I want to take the last thing in that url and save in a String.
The url is like
C:\Music\Song.mp3
I've come up with this:
String name[] = urlString.Split("'\'");
System.out.println(name[0]);
Which gives me:
"C:\Music\Song.mp3"
But what can I use to save "Song.mp3" to a string?
Thanks
- 05-29-2011, 08:39 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,380
- Blog Entries
- 7
- Rep Power
- 17
- 05-29-2011, 08:46 PM #3
Member
- Join Date
- Nov 2010
- Posts
- 24
- Rep Power
- 0
-
That's because lastIndexOf returns an int. Then you can use that int to get the proper subString.
You could also still split the String, but realize that the parameter to the split method is a regular expression, and so you need to use "\\\\":
Java Code:String urlString = "C:\\Music\\Song.mp3"; String[] tokens = urlString.split("\\\\"); System.out.println(tokens[tokens.length - 1]);Last edited by Fubarable; 05-29-2011 at 08:51 PM.
- 05-29-2011, 08:49 PM #5
Member
- Join Date
- Nov 2010
- Posts
- 24
- Rep Power
- 0
- 05-29-2011, 09:02 PM #6
Member
- Join Date
- Nov 2010
- Posts
- 24
- Rep Power
- 0
Thanks, I got it all sorted now!
- 05-29-2011, 09:02 PM #7
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,380
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
No of a specific char in a string
By alinaqvi90 in forum New To JavaReplies: 13Last Post: 05-27-2010, 07:59 AM -
giving missing return statement error.due to withdraw method.
By qadeer37 in forum New To JavaReplies: 5Last Post: 01-16-2010, 11:14 PM -
HashMaps get key for a specific value
By andre1011 in forum Advanced JavaReplies: 2Last Post: 03-11-2009, 02:30 AM -
how do i print a specific txt file on a specific printer
By nikhilbhat in forum New To JavaReplies: 2Last Post: 11-08-2008, 10:40 AM -
How to cast an Object into a specific type (Integer/String) at runtime
By mailtogagan@gmail.com in forum Advanced JavaReplies: 2Last Post: 12-03-2007, 01:04 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks