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

Something like this should do:

s = 'xxxxx - xxxxx'
space = ' '
nospace = ''
s = s.replace(space, nospace)
print s  # xxxxx-xxxxx
>>> s = 'XXXXX -\n\t XXXX'
>>> ''.join(s.split())
'XXXXX-XXXX'
>>>
commented: nice solution! +4

Thanks a lot. Its working now.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.