This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "how to split" Watch "how to split" New topic
Author

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
    
    1

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.

HTH


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to split
 
Similar Threads
image not displaying in tomcat server
relative URL in jar files
Is there a way I can store pictures/sounds into my Jar file?
JApplet + JPanel + image.jpg
Displaying a random picture in a JSP file