本文介绍了拆分字符串时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有一串数字和单词如 '',,,,,, 23 ,,,,,,,,,姓氏,,,,,,, \ n'' 我想拆分(我是使用string.split())它使用逗号作为 分隔符,但我不想分成两个也是name,surname 字段。换句话说,我希望python在分隔字段中跳过 那个特殊的逗号。 我该怎么做? 提前致谢 Angelo - ======== ========================================== ====== Angelo Secchi PGP密钥ID:EA280337 ============================= ===================== ====== 当前位置: 研究员Scuola Superiore S.Anna Piazza Martiri della Liberta''33,Pisa,56127意大利 ph。:+ 39 050 883365 电子邮件: se **** @ssup.it www.sssup.it/~secchi/ ==================== ============================== ====== 解决方案 Angelo, 例如,你如何分析给予 的例子? wes Angelo,例如你怎么想把这个例子分开来? wes - http://mail.python.org/mailman/listinfo/python-list - = ================================================= = ===== Angelo Secchi PGP密钥ID:EA280337 ====================== ============================ ====== 当前位置: 研究员Scuola Superiore S.Anna Piazza Martiri della Liberta''33,Pisa,56127意大利 电话:+39 050 883365 电子邮件: se****@sssup.it www.sssup.it/~secchi/ ============= ===================================== ====== Angelo,Hi,I have string of numbers and words like'',,,,,,23,,,asd,,,,,"name,surname",,,,,,,\n''and I would like to split (I''m using string.split()) it using comma asseparator but I do not want to split in two also the "name,surname"field. In other word I would like python in separating fields to skipthat particular comma.How can I do that?Thanks in advanceAngelo--================================================== ======Angelo Secchi PGP Key ID:EA280337================================================== ======Current Position:Graduate Fellow Scuola Superiore S.AnnaPiazza Martiri della Liberta'' 33, Pisa, 56127 Italyph.: +39 050 883365email: se****@sssup.it www.sssup.it/~secchi/================================================== ====== 解决方案Angelo,For example, how how would you want the example given tobe split?wes Angelo, For example, how how would you want the example given to be split? wes -- http://mail.python.org/mailman/listinfo/python-list--================================================== ======Angelo Secchi PGP Key ID:EA280337================================================== ======Current Position:Graduate Fellow Scuola Superiore S.AnnaPiazza Martiri della Liberta'' 33, Pisa, 56127 Italyph.: +39 050 883365email: se****@sssup.it www.sssup.it/~secchi/================================================== ======Angelo,Could you split the strings; then recombine list[14] + '','' + list[15] ?wes 这篇关于拆分字符串时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-15 11:09