拆分字符串时出现问题 [英] Problem in splitting a string
问题描述
我有一串数字和单词如
'',,,,,, 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 Secchi写道:
我有一串数字和单词如
'',,,,,, 23 ,,, asd ,,,,," name,surname" ,,,,,,, \ n''
我想分裂(我正在使用string.split())它使用逗号作为
分隔符,但我不想分成两个也是name,surname
字段。换句话说,我希望python在分隔字段中跳过那个特殊的逗号。
我该怎么做?
提前致谢
<安吉洛
-
================================ ================== ======
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,
例如,你如何分析给予
的例子?
wes
谢谢,Wes。我希望我的例子中的tring分裂为:
['''','''',''''等等,''23'',' ''','''',''" name,surname"'','''','''',''''等等,''\ n''] >
再次感谢
angelo
2004年7月22日星期四18:23:56 GMT
wes weston< ww ***** @ att.net>写道:
Angelo Secchi写道:
我有一串数字和单词,如
'' ,,,,,, 23 ,,, asd ,,,,," name,surname" ,,,,,,, \ n''
我想拆分(我''正在使用string.split())它使用逗号
作为分隔符,但我不想将其分成两部分
" name,surname"领域。换句话说,我希望python在
分隔字段中跳过那个特殊的逗号。
我该怎么做?
提前致谢
<安吉洛
-
================================ ================== ======
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,
例如你怎么想把这个例子分开来?
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 Secchi写道:
我有一串数字和单词,如
'',,,,,, 23 ,,, asd ,,,,," name,surname" ,,,,,,, \ n''
我想拆分(我正在使用字符串。小号plit())它使用逗号作为
分隔符,但我不想分成两个也是name,surname
字段。换句话说,我希望python在分隔字段中跳过那个特殊的逗号。
我该怎么做?
提前致谢
<安吉洛
-
================================ ================== ======
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,
list ='',,,,,, 23 ,,, asd ,,,,," name,surname" ,, ,,,,, \ n''。split(' ,''打印清单
['''','''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ,'''','''','''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ',''','''','''','''''''''''''''''''''''''''' blockquote>
你能分割字符串吗?然后重新组合列表[14] +'',''+列表[15]?
wes
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 as
separator 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 skip
that particular comma.
How can I do that?
Thanks in advance
Angelo
--
================================================== ======
Angelo Secchi PGP Key ID:EA280337
================================================== ======
Current Position:
Graduate Fellow Scuola Superiore S.Anna
Piazza Martiri della Liberta'' 33, Pisa, 56127 Italy
ph.: +39 050 883365
email: se****@sssup.it www.sssup.it/~secchi/
================================================== ======解决方案Angelo Secchi wrote: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 as
separator 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 skip
that particular comma.
How can I do that?
Thanks in advance
Angelo
--
================================================== ======
Angelo Secchi PGP Key ID:EA280337
================================================== ======
Current Position:
Graduate Fellow Scuola Superiore S.Anna
Piazza Martiri della Liberta'' 33, Pisa, 56127 Italy
ph.: +39 050 883365
email: se****@sssup.it www.sssup.it/~secchi/
================================================== ======
Angelo,
For example, how how would you want the example given to
be split?
wes
Thanks, Wes. I would like the tring in my example splitted as:
['''','''','''',and so on,''23'','''','''',''"name,surname"'','''','''','''',and so on,''\n'']
Thanks again
angelo
On Thu, 22 Jul 2004 18:23:56 GMT
wes weston <ww*****@att.net> wrote:
Angelo Secchi wrote: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
as separator 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 skip that particular comma.
How can I do that?
Thanks in advance
Angelo
--
================================================== ======
Angelo Secchi PGP Key ID:EA280337
================================================== ======
Current Position:
Graduate Fellow Scuola Superiore S.Anna
Piazza Martiri della Liberta'' 33, Pisa, 56127 Italy
ph.: +39 050 883365
email: se****@sssup.it www.sssup.it/~secchi/
================================================== ======
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.Anna
Piazza Martiri della Liberta'' 33, Pisa, 56127 Italy
ph.: +39 050 883365
email: se****@sssup.it www.sssup.it/~secchi/
================================================== ======
Angelo Secchi wrote: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 as
separator 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 skip
that particular comma.
How can I do that?
Thanks in advance
Angelo
--
================================================== ======
Angelo Secchi PGP Key ID:EA280337
================================================== ======
Current Position:
Graduate Fellow Scuola Superiore S.Anna
Piazza Martiri della Liberta'' 33, Pisa, 56127 Italy
ph.: +39 050 883365
email: se****@sssup.it www.sssup.it/~secchi/
================================================== ======
Angelo,
list = '',,,,,,23,,,asd,,,,,"name,surname",,,,,,,\n''.split ('','')
print list ['''', '''', '''', '''', '''', '''', ''23'', '''', '''', ''asd'', '''', '''', '''', '''', ''"name'', ''surname"'', '''', '''', '''', '''', '''', '''', ''\n'']
Could you split the strings; then recombine list[14] + '','' + list[15] ?
wes
这篇关于拆分字符串时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!