

可以使用 Python 来实现这个功能。下面是一个简单的实现方法:
def capitalize_title(title: str) -> str:
words = title.split() # 按空格分割字符串
result = []
for word in words:
if len(word) <= 2:
result.append(word.lower()) # 长度为1或2,全部小写
else:
result.append(word.capitalize()) # 首字母大写,其余小写
return ' '.join(result)
示例:
print(capitalize_title("tHis is a tEst")) # 输出: "This is a Test"
print(capitalize_title("HELLO woRLd py")) # 输出: "Hello World py"
1746

被折叠的 条评论
为什么被折叠?



