Constant Case Converter

Enter text to convert it to CONSTANT_CASE.

How it is calculated

The tool works in three passes. First it inserts a break wherever a lowercase letter or digit is followed by a capital (requestTimeout becomes request Timeout), and wherever a run of capitals is followed by a capital plus lowercase (XMLHttp becomes XML Http). Then it splits the text on every run of characters that is not a letter, digit or combining mark in any script, so spaces, hyphens, underscores and punctuation all act as separators. Finally it uppercases the pieces and joins them with _, and reports the number of pieces (tokens). Accented and non-Latin letters are kept and uppercased (şehir adı becomes ŞEHIR_ADI). Leading and trailing separators are dropped, and input with no letters or digits gives no result.

Worked example

Input: max retry-count requestTimeout. Step 1, split camelCase: max retry-count request Timeout. Step 2, split on spaces and the hyphen: max, retry, count, request, Timeout, which is 5 tokens. Step 3, uppercase and join with underscores: MAX_RETRY_COUNT_REQUEST_TIMEOUT. The tool shows the count as 5 tokens and repeats your original text beside the result.

Try this example →

Common mistakes

  • Expecting digits to stay attached to a following capital: 2FA becomes 2_FA and user2Name becomes USER2_NAME, because a digit followed by a capital counts as a boundary.
  • Assuming acronyms are always split the way your style guide wants: getHTTPResponse becomes GET_HTTP_RESPONSE, but parseHTML5Doc gives PARSE_HTML5_DOC, which may not match your own convention.
  • Expecting a leading underscore to survive: _private_ becomes PRIVATE, so private-member markers must be added back by hand.
  • Pasting non-ASCII text into a constant name and using it as-is: letters such as Ş or Cyrillic are kept, but many languages and tools only allow ASCII identifiers, so transliterate first.
  • Entering only punctuation or symbols (for example ---); there is no word to convert, so no result appears.

About this calculator

CONSTANT_CASE (also called UPPER_SNAKE_CASE) writes identifiers as all-uppercase words separated by underscores, such as MAX_RETRY_COUNT or API_BASE_URL. Converting to it means splitting the input on spaces, hyphens, underscores, and camelCase word boundaries (the point where a lowercase letter meets an uppercase one), then uppercasing each word and rejoining them with underscores.

This naming convention is a long-standing style-guide rule in languages like C, Java, Python, and JavaScript, where it signals that an identifier is a compile-time constant or an enum value — distinguishing it at a glance from ordinary camelCase variables or PascalCase types.

Was this helpful?

You can pick up to 3 reactions.

Comments (1)

  • Editorial team

    Words are split at lowercase-to-capital boundaries and at anything that is not a letter or digit, then joined with underscores, so userID becomes USER_ID and a version like v2.1 becomes V2_1. Punctuation, including hyphens, is dropped. Letters from any script are kept. Which naming style does your codebase use for constants, and where does this split surprise you?

Popular calculators

All Calculators