954,152 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

collapse white space in string

I would like to collapse whitespace in a string of the followinf foramat using a some pre defined functionalities.

XXXXX-XXXX shoud be converted to XXXXX-XXXXX
XXXXX-XXXXX shoud be converted to XXXXX-XXXXX

Please help

dinilkarun
Posting Whiz in Training
206 posts since Feb 2008
Reputation Points: 18
Solved Threads: 0
 
mengqing
Newbie Poster
5 posts since May 2008
Reputation Points: 10
Solved Threads: 1
 

Something like this should do:

s = 'xxxxx - xxxxx'
space = ' '
nospace = ''
s = s.replace(space, nospace)
print s  # xxxxx-xxxxx
Ene Uran
Posting Virtuoso
1,722 posts since Aug 2005
Reputation Points: 625
Solved Threads: 212
 
>>> s = 'XXXXX -\n\t XXXX'
>>> ''.join(s.split())
'XXXXX-XXXX'
>>>
solsteel
Junior Poster
145 posts since Mar 2007
Reputation Points: 86
Solved Threads: 42
 

Thanks a lot. Its working now.

dinilkarun
Posting Whiz in Training
206 posts since Feb 2008
Reputation Points: 18
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You