File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes How to use Delimter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to use Delimter" Watch "How to use Delimter" New topic
Author

How to use Delimter

Neeba Rebbaca
Ranch Hand

Joined: Oct 21, 2008
Posts: 151
I want to split a string using " ( " as a delimiter.

My code for that is :


but its throwing error as "Exception in thread "main" java.util.regex.PatternSyntaxException: Unmatched closing ')'
)"


How to mention a backet as a delimiter??

Thank you
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

The argument that you pass to the split method is a regular expression, and ( has a special meaning in regular expressions. You need to escape it:


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Neeba Rebbaca
Ranch Hand

Joined: Oct 21, 2008
Posts: 151
Jesper Young wrote:The argument that you pass to the split method is a regular expression, and ( has a special meaning in regular expressions. You need to escape it:



Thank You.

Suppose if i have more than one delimiter how can i split it at a time??

Is there any way for it or i have to split it sperately???
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

Neeba Rebbaca wrote:Suppose if i have more than one delimiter how can i split it at a time??

Write a regular expression that matches all the characters or character sequences that you want to be recognised as delimiters.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to use Delimter
 
Similar Threads
explode() in Java?
splitting arrays
Regex and Generics Notes/Questions
doubt in string.split method
Reading and Modifying a Big CSV file