Constant Case Converter
Enter text to convert it to CONSTANT_CASE.
Result
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.
Common mistakes
- Expecting digits to stay attached to a following capital:
2FAbecomes2_FAanduser2NamebecomesUSER2_NAME, because a digit followed by a capital counts as a boundary. - Assuming acronyms are always split the way your style guide wants:
getHTTPResponsebecomesGET_HTTP_RESPONSE, butparseHTML5DocgivesPARSE_HTML5_DOC, which may not match your own convention. - Expecting a leading underscore to survive:
_private_becomesPRIVATE, 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.
Popular calculators
Loan Calculator
Monthly payment, total interest and full amortization schedule.
Percentage Calculator
Percent change, percent of, and ratio calculations.
Discount Calculator
Calculate final price, savings, and discount amount.
BMI Calculator
Body mass index from height and weight (metric or imperial).
Age Calculator
Compute your exact age in years, months and days from a birth date.
Compound Interest Calculator
Calculate the final amount and interest earned with compounding.
All Calculators
- Loan Calculator
- Profit Calculator
- Discount Calculator
- BMI Calculator
- Percentage Calculator
- Ideal Weight Calculator
- Age Calculator
- Pregnancy Due Date Calculator
- Compound Interest Calculator
- BMR Calculator (Basal Metabolic Rate)
- Tip Calculator
- Fuel Cost Calculator
- Date Difference Calculator
- Sleep Cycle Calculator
- Daily Water Intake Calculator
- Simple Interest Calculator
- Heart Rate Zones Calculator
- Running Pace Calculator
- Pet Age Calculator
- Calories Burned Calculator
- Macro Calculator
- TDEE Calculator (Total Daily Energy Expenditure)
- Waist-to-Hip Ratio Calculator
- Honor Roll Calculator
- One Rep Max (1RM) Calculator
- Ovulation Calculator
- Electricity Cost Calculator
- Unit Price Calculator
- Savings Goal Calculator
- Break-Even Point Calculator
- Paint Calculator
- Course Grade Average Calculator
- Business Days Calculator
- Time Duration Calculator
- Fuel Economy Calculator
- Temperature Converter
- Tile Calculator
- Aspect Ratio Calculator
- Roman Numeral Converter
- Goal Weight Timeline Calculator
- Salary Converter (Hourly to Annual)
- Credit Card Validator (Luhn)
- Body Surface Area (BSA) Calculator
- Feels-Like Temperature Calculator
- Ohm’s Law Calculator
- PPI (Pixel Density) Calculator
- Molar Mass Calculator
- Zodiac Sign Calculator (Western + Chinese)
- IBAN Validator
- Shoe Size Converter
- Country Info & Dialing Code Lookup
- Time Zone Difference (World Clock)
- CAGR (Compound Annual Growth Rate) Calculator
- Rule of 72 Calculator
- Blood Alcohol Content (BAC) Calculator
- Lean Body Mass (LBM) Calculator
- Pythagorean Theorem Calculator
- Speed Converter
- Download Time Calculator
- Date Calculator (Add/Subtract)
No calculators found
Comments (1)
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?