Get the tools you need to learn Java skills fast!
Video tutorials, eBooks, hands-on lab exercises, sample code.
Get started
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes how to split Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Badass: Making Users Awesome this week in the Game Development forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "how to split" Watch "how to split" New topic

how to split

Saurabh Naik
Ranch Hand

Joined: Apr 24, 2008
Posts: 87
suppose this is mystring = c:\my\you\image.jpg

and I want only image.jpg.

so I hav used mystring.split("\") or ("\\");

but its giving me exception java.util.regex.patternsyntaxexception: Unexpected internal error near index 1 \^

SCJP 6 (88%), SCWCD 5 (78%), preparing for SCBCD
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902

Saurabh Naik wrote:suppose this is mystring = c:\my\you\image.jpg

and I want only image.jpg.

If you want only name of the file, then I suggest don't go for split method, instead use String#subString(int, int0 method, the first parameter is the index of last "\"(String has a method for this, search Java Docs) and second param is length of string.


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
I agree. Here's the link:
subject: how to split