• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to allow 1 white spaces in beetween only in trim?  RSS feed

 
Ranch Hand
Posts: 72
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


how can i allow 1 spaces only in bettween on trim? that's the code the i used to trim thank you what i want to happen is to have only 1 spaces in beetween
 
Author and ninkuma
Marshal
Posts: 66351
155
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
$.trim() only removes leading and trailing whitespace. It will not collapse interior spaces. Please check documentation before posting.
 
author & internet detective
Marshal
Posts: 37708
578
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the goal is to remove extra spaces, you could do a search and replace. If you use a regular expression, you can match "1 or more spaces" and replace that match with one space.
 
Ranch Hand
Posts: 44
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This may not be efficient approach but solve the problem. You may want to try regex for the same.



Using regular expressions will be more efficient i believe.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!