Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

split() throws PatternsyntaxException  RSS feed

 
naveen yadav
Ranch Hand
Posts: 384
Java MyEclipse IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ranchers,

i have a String of a location like "dir\\filename" .I want to separate the directory name from file name for which i use the following code



But it throws PatternsyntaxException. why ? it seems to me that split() having a problem with "\\".
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
\ is a special character in Java string literals and in regular expressions. Which means you have to escape it twice!
 
naveen yadav
Ranch Hand
Posts: 384
Java MyEclipse IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
bingo !!
thanks Matthew Brown
 
Wendy Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you could also consider using FILE, that has loads of methods to do this sort of stuff.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!