2013-04-26 24 views

cevap

75

Sen strip öyle değil replace istiyorum o: dizeleri

s = s.replace(',', '') 
+3

Bahse girerim birisi bunun bir düzenli ifadesini yayınlayacak ... – jamylak

+10

@jamylak 's = re.sub (',', '', s)';) – Kiro

9

Kullanım replace yöntem değildir strip:

s = s.replace(',','') 

Bir örnek:

>>> s = 'Foo, bar' 
>>> s.replace(',',' ') 
'Foo bar' 
>>> s.replace(',','') 
'Foo bar' 
>>> s.strip(',') # clears the ','s at the start and end of the string which there are none 
'Foo, bar' 
>>> s.strip(',') == s 
True 
+0

Man! Çok açık! ÇOK AÇIK! Ama çok açık ki strip kullanıyordum ve neden bir toplu iş olarak işe yaramadığını anlamaya çalışıyor ... –

3

unicode('foo,bar').translate(dict([[ord(char), u''] for char in u',']))

+0

+1 hahahah umarım bu bir şakaydı – jamylak

İlgili konular