Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

which string function to remove whitespace between two strings  RSS feed

 
pavithra murthy
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello ,

i want to remove spaces between 2 strings .

the trim function in string will remove only leading and trailing whitespaces.

but is there any string function in java such that the for example

str=" javahorn forum"

i want to remove the whitespace between javahorn and forum such that it displays as

str=" javahornforum"
 
Campbell Ritchie
Marshal
Posts: 55799
164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look for the replace and replaceAll methods. You may require an understanding of refular expressions.
 
sridhar vedhanabatla
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using regular expressions might help you in long term.

But for quick getting quick results without spending too much resources in writing good regexes you can alternatively try Apache string util api at http://commons.apache.org/lang/apidocs/org/apache/commons/lang/StringUtils.html for several string processing functions.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!