• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to split

 
Saurabh Naik
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 \^
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic