python中的TCL多字符分开?
我正在使用此 tcl 过程拆分文本文件:
proc mcsplit "str splitStr {mc {\x00}}" {
return [split [string map [list $splitStr $mc] $str] $mc] }
# mcsplit --
# Splits a string based using another string
# Arguments:
# str string to split into pieces
# splitStr substring
# mc magic character that must not exist in the orignal string.
# Defaults to the NULL character. Must be a single character.
# Results:
# Returns a list of strings
split
命令根据 splitString
中的每个字符拆分字符串。此版本将 splitString 作为组合字符串处理,将字符串拆分为组成部分, 但我的目标是使用 python 做同样的事情,这里有人以前做过同样的事情吗?
I am splitting a text file using this tcl proc:
proc mcsplit "str splitStr {mc {\x00}}" {
return [split [string map [list $splitStr $mc] $str] $mc] }
# mcsplit --
# Splits a string based using another string
# Arguments:
# str string to split into pieces
# splitStr substring
# mc magic character that must not exist in the orignal string.
# Defaults to the NULL character. Must be a single character.
# Results:
# Returns a list of strings
The split
command splits a string based on each character that is in the splitString
. This version handles the splitString
as a combined string, splitting the string into constituent parts,
but my objective is to do the same using python does anyone here did the same before?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从您的问题中还不清楚 python
split
行为是否是您所需要的。如果您需要在每次出现多字符字符串时进行拆分,Python 的常规split
就可以完成这项工作:但是,如果您希望在出现多个单个时进行拆分> 字符,您需要使用
re.split
:It's not very clear from your question whether the python
split
behavior is what you need. If you need to split at each occurrence of a multiple-character string, Python's regularsplit
will do the job:If, however, you want to split at any occurrence of multiple individual characters, you'll need to use
re.split
: