大小写转换
将文本转换为 UPPERCASE、lowercase、Title Case、camelCase 等格式。
UPPERCASE
结果将显示在此处...
lowercase
结果将显示在此处...
Title Case
结果将显示在此处...
Sentence case
结果将显示在此处...
camelCase
结果将显示在此处...
snake_case
结果将显示在此处...
kebab-case
结果将显示在此处...
aLtErNaTiNg
结果将显示在此处...
大小写转换器可将文本即时转换为不同的字母大小写格式。无论您需要标题的大写、电子邮件地址的小写、书名的标题大小写,还是编程变量名的驼峰命名法,此工具都能处理所有常见的大小写转换。
粘贴您的文本并选择所需的输出格式。支持的转换包括:大写(全部大写)、小写(全部小写)、标题大小写、句子大小写、驼峰命名法、帕斯卡命名法、下划线命名法和连字符命名法。
大小写转换在编程工作流中特别有用,不同语言的命名规范各不相同:JavaScript 变量使用驼峰命名法,Python 使用下划线命名法,CSS 使用连字符命名法,大多数面向对象语言使用帕斯卡命名法作为类名。
常见问题
代码实现
import re
def to_words(text: str) -> list[str]:
"""Split text into words, handling camelCase, snake_case, kebab-case, and spaces."""
text = re.sub(r"([a-z])([A-Z])", r"\1 \2", text) # camelCase split
text = re.sub(r"[_\-]+", " ", text) # snake/kebab to space
return [w for w in text.strip().split() if w]
def to_camel_case(text: str) -> str:
words = to_words(text)
return words[0].lower() + "".join(w.capitalize() for w in words[1:])
def to_pascal_case(text: str) -> str:
return "".join(w.capitalize() for w in to_words(text))
def to_snake_case(text: str) -> str:
return "_".join(w.lower() for w in to_words(text))
def to_kebab_case(text: str) -> str:
return "-".join(w.lower() for w in to_words(text))
def to_screaming_snake(text: str) -> str:
return "_".join(w.upper() for w in to_words(text))
# Example usage
text = "hello world example"
print(to_camel_case(text)) # helloWorldExample
print(to_pascal_case(text)) # HelloWorldExample
print(to_snake_case(text)) # hello_world_example
print(to_kebab_case(text)) # hello-world-example
print(to_screaming_snake(text)) # HELLO_WORLD_EXAMPLE
Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.