Python 3 字符串方法?
无论如何,是否可以在单个字符串中从一个索引删除或替换或类似的操作到另一个索引?
例如,如果我有一个像“first - Second - Third”这样的字符串,并且我想删除中间部分(“ - Second - ”),我该怎么做?
提前致谢。
Is there anyway to strip or replace or anything like that from one index to another index within a single string?
For example, if I have a string like "first - second - third" and I want to remove the middle part (" - second - "), how could I do this?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的字符串:
以及可能的解决方案:
或者
或者
或者如果您知道索引:
或者只是搜索第一个和最后一个空格:
它们都返回
'firstthird'
Your string:
and the possible solutions:
or
or
or if you know the indices:
or just searching for the first and last space:
all of them return
'firstthird'
如果要删除的索引是 (i, j),那么您可以这样做:
If the indices to remove are (i, j), then you could do with: