This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
    Bookmark Topic Watch Topic
  • New Topic

trim method help

 
adeeb alexander
Ranch Hand
Posts: 268
  • 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: 20605
60
Chrome Eclipse IDE Java Windows
  • 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: 20605
60
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator
Let's continue here.
 
    Bookmark Topic Watch Topic
  • New Topic