跳到主要内容
uencoder

如何Convert Text Case

Transform 文本之间 camelCase, snake_case, kebab-情况, PascalCase, 和更多.

问题

你有 文本在 one naming 约定和 need 它在 另一个为 不同 programming language 或风格指南.

前置条件

  • Understanding 的 naming conventions
  • 熟悉字 boundaries

步骤

  1. 1. Identify the source convention

    Determine the current case: camelCase (lowercase first, capitals at word boundaries), snake_case (underscores), kebab-case (hyphens), PascalCase (capital first), or SCREAMING_SNAKE. Detecting the source convention correctly is essential for accurate conversion.

    输入
    camelCase: myVariableName
    输出
    convention identified
  2. 2. Split into words

    Parse the text into individual words by detecting boundaries: underscores, hyphens, capital letters (for camelCase/PascalCase), or spaces. Handle consecutive capitals carefully (e.g., 'HTTPServer' → 'HTTP' + 'Server').

    输入
    myVariableName
    输出
    words: [my, Variable, Name]
  3. 3. Rejoin in the target convention

    Combine the words using the target convention's separator and capitalization. For snake_case, join with underscores in lowercase. For camelCase, lowercase the first word and capitalize the rest. For kebab-case, join with hyphens in lowercase.

    输入
    words + target: snake_case
    输出
    my_variable_name

预期结果

Text 正确 converted 到目标 naming 约定.

常见错误

Consecutive capitals split incorrectly
Words like 'XMLParser' should split into 'XML' and 'Parser', not 'X', 'M', 'L', 'Parser'. Use a converter that handles consecutive capitals intelligently.
Acronyms lowercased incorrectly
Some conventions preserve acronyms (e.g., 'parseXML' not 'parseXml'). Check your converter's acronym handling.

排障指引

  • If the output looks wrong, check how the source was split into words.
  • Test with edge cases like single words, all-caps, and mixed separators.

安全限制

  • Case conversion is a pure text transformation with no security implications.

相关工具

参考链接