collapse white space in string

Thread Solved

Join Date: Feb 2008
Posts: 198
Reputation: dinilkarun is an unknown quantity at this point 
Solved Threads: 0
dinilkarun dinilkarun is offline Offline
Junior Poster

collapse white space in string

 
0
  #1
Jul 1st, 2008
I would like to collapse whitespace in a string of the followinf foramat using a some pre defined functionalities.

XXXXX<space>-<space>XXXX shoud be converted to XXXXX-XXXXX
XXXXX<space>-XXXXX shoud be converted to XXXXX-XXXXX

Please help
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 5
Reputation: mengqing is an unknown quantity at this point 
Solved Threads: 1
mengqing mengqing is offline Offline
Newbie Poster

Re: collapse white space in string

 
0
  #2
Jul 1st, 2008
-
Last edited by mengqing; Jul 1st, 2008 at 10:35 am.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 1,542
Reputation: Ene Uran has a spectacular aura about Ene Uran has a spectacular aura about 
Solved Threads: 173
Ene Uran's Avatar
Ene Uran Ene Uran is offline Offline
Posting Virtuoso

Re: collapse white space in string

 
0
  #3
Jul 1st, 2008
Something like this should do:
  1. s = 'xxxxx - xxxxx'
  2. space = ' '
  3. nospace = ''
  4. s = s.replace(space, nospace)
  5. print s # xxxxx-xxxxx
drink her pretty
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 110
Reputation: solsteel is on a distinguished road 
Solved Threads: 31
solsteel solsteel is offline Offline
Junior Poster

Re: collapse white space in string

 
1
  #4
Jul 1st, 2008
  1. >>> s = 'XXXXX -\n\t XXXX'
  2. >>> ''.join(s.split())
  3. 'XXXXX-XXXX'
  4. >>>
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 198
Reputation: dinilkarun is an unknown quantity at this point 
Solved Threads: 0
dinilkarun dinilkarun is offline Offline
Junior Poster

Re: collapse white space in string

 
0
  #5
Jul 3rd, 2008
Thanks a lot. Its working now.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Python Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC