User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Python section within the Software Development category of DaniWeb, a massive community of 403,518 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,844 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Python advertiser: Programming Forums
Views: 343 | Replies: 4 | Solved
Reply
Join Date: Feb 2008
Posts: 84
Reputation: dinilkarun is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
dinilkarun dinilkarun is offline Offline
Junior Poster in Training

collapse white space in string

  #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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2008
Posts: 5
Reputation: mengqing is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 1
mengqing mengqing is offline Offline
Newbie Poster

Re: collapse white space in string

  #2  
Jul 1st, 2008
-
Last edited by mengqing : Jul 1st, 2008 at 9:35 am.
Reply With Quote  
Join Date: Aug 2005
Posts: 1,051
Reputation: Ene Uran is an unknown quantity at this point 
Rep Power: 6
Solved Threads: 65
Ene Uran's Avatar
Ene Uran Ene Uran is offline Offline
Veteran Poster

Re: collapse white space in string

  #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  
Join Date: Mar 2007
Posts: 43
Reputation: solsteel is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 12
solsteel solsteel is offline Offline
Light Poster

Re: collapse white space in string

  #4  
Jul 1st, 2008
>>> s = 'XXXXX -\n\t XXXX'
>>> ''.join(s.split())
'XXXXX-XXXX'
>>> 
Reply With Quote  
Join Date: Feb 2008
Posts: 84
Reputation: dinilkarun is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
dinilkarun dinilkarun is offline Offline
Junior Poster in Training

Re: collapse white space in string

  #5  
Jul 3rd, 2008
Thanks a lot. Its working now.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Python Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Python Forum

All times are GMT -4. The time now is 1:06 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC