2024-06-16 12:44:15 发布
网友
我有下面的字符串。我想在角色之前得到一切
'abc eff 23 aaa|C:\\WINDOWS|\\Device\\Harddisk\\Parti'
我的输出应该是“abc eff 23 aaa”
我怎么得到它。。请帮我做这个
您可以使用内置的“拆分”功能:
'abc eff 23 aaa|C:\\WINDOWS|\\Device\\Harddisk\\Parti'.split('|')[0]
Here is the documentation on how it works if you are curious
这里有两种方法可以使用string.split('|')[0]或string[:string.find('|')](字符串是数组,您也可以这样做)
string.split('|')[0]
string[:string.find('|')]
您可以使用内置的“拆分”功能:
Here is the documentation on how it works if you are curious
这里有两种方法可以使用
string.split('|')[0]
或string[:string.find('|')]
(字符串是数组,您也可以这样做)相关问题 更多 >
编程相关推荐