2005年09月05日 星期一 12:35
现在获得了一个字符串,但中间有很多不连续的无用空格
 现在想把这些空格去掉,不知道有没有现成的函数
 想用replace函数
 但用string.replace(" ","")没有达到效果
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20050905/b24cf337/attachment.html
2005年09月05日 星期一 12:39
在 05-9-5,Lee DYER<lee.dyer at gmail.com> 写道: > 现在获得了一个字符串,但中间有很多不连续的无用空格 > > 现在想把这些空格去掉,不知道有没有现成的函数 > > 想用replace函数 > > 但用string.replace(" ","")没有达到效果 > string.replace要重新赋值才可以。因为string是不可改变的。 -- I like python! My Donews Blog: http://www.donews.net/limodou
2005年09月05日 星期一 13:02
是说要
string = string.replace(" ","")
在05-9-5,limodou <limodou at gmail.com> 写道:
> 
> 在 05-9-5,Lee DYER<lee.dyer at gmail.com> 写道:
> > 现在获得了一个字符串,但中间有很多不连续的无用空格
> >
> > 现在想把这些空格去掉,不知道有没有现成的函数
> >
> > 想用replace函数
> >
> > 但用string.replace(" ","")没有达到效果
> >
> 
> string.replace要重新赋值才可以。因为string是不可改变的。
> 
> --
> I like python!
> My Donews Blog: http://www.donews.net/limodou
> 
> _______________________________________________
> python-chinese list
> python-chinese at lists.python.cn
> http://python.cn/mailman/listinfo/python-chinese
> 
> 
> 
-- 
人生总是要有一些理想的
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20050905/9fd9f4d3/attachment.htm
2005年09月05日 星期一 13:04
在05-9-5,黄斌 <huangbin2005 at gmail.com> 写道: > > 是说要 > string = string.replace(" ","") > > 恩,明白的,一下子没记起来原来的字符串是不改变的 > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20050905/497b7197/attachment.html
2005年09月05日 星期一 15:28
在 05-9-5,Lee DYER<lee.dyer at gmail.com> 写道: > 现在获得了一个字符串,但中间有很多不连续的无用空格 > > 现在想把这些空格去掉,不知道有没有现成的函数 可以自己写个函数吧: >>> StringReplace = lambda x: ''.join(x.split(' ')) >>> StringReplace('asd asdf as d') 'asdasdfasd'
2005年09月06日 星期二 08:50
可以参考一下Python的source code, 这个lambda的效率应该比replace低很多的。 On 9/5/05, makeyunbad <makeyunbad at gmail.com> wrote: > > 在 05-9-5,Lee DYER<lee.dyer at gmail.com> 写道: > > 现在获得了一个字符串,但中间有很多不连续的无用空格 > > > > 现在想把这些空格去掉,不知道有没有现成的函数 > > 可以自己写个函数吧: > >>> StringReplace = lambda x: ''.join(x.split(' ')) > >>> StringReplace('asd asdf as d') > 'asdasdfasd' > > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20050906/d7eea1a1/attachment.html
Zeuux © 2025
京ICP备05028076号