【发布时间】:2026-01-25 04:05:01
【问题描述】:
需要泛化解决方案
我有一个字符串,想删除冒号前的所有字符 (:)。像这样:
oldstring = 'Resolution: 1366 x 768'
newstring = '1366 x 768'
【问题讨论】:
-
试试
newstring = oldstring.replace('Resolution: ', '') -
我需要所有字符串的通用解决方案
-
是否还要删除冒号后的所有空格?
-
如果输入是“纵横比:16:9”,预期的输出是什么?
-
如果
:之前的内容不同,则只需newstring = oldstring.split(':')[1].strip()