File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
    Bookmark Topic Watch Topic
  • New Topic

trim method help

 
adeeb alexander
Ranch Hand
Posts: 268
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi.
Consider these values "apple fruit, grapes fruit, onion veg , meat non-veg". Now how can i trim just the spaces or tabs before and after the comma. I need the spaces in between the values. I have tried using the split method and then trim the spaces to do this i have to split each and every value is there any other way.


Thanks and Regards
alexander.
 
Rob Spoor
Sheriff
Pie
Posts: 20369
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
Do you need an array, or just a string with the spaces removed?

Either way, the regular expression to use is ",\\s+" - a comma followed by one or more occurrences of whitespace. Splitting would be done as follows:
Replacing:


This thread is more suitable for the intermediate forum, moving there.
 
Rob Spoor
Sheriff
Pie
Posts: 20369
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
Let's continue here.
 
    Bookmark Topic Watch Topic
  • New Topic