ForHosting KIT · Developer Utilities

C string escaper

A stray double quote, backslash or line break can break a C string; this tool turns Hello "world", a new line and line 2 into Hello \"world\"\nline 2, ready to paste into source. It also reverses escapes and stops at malformed ones. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon
If you enter
Text
Hello "world" line 2
Calculation mode
Escape
Quote
Double
You get
Result
Hello \"world\"\nline 2
Length
23
Literal
"Hello \"world\"\nline 2"

Embedding free text inside a C or C++ string literal is a classic footgun: a single double quote ends the string, a bare backslash swallows the next character, a raw newline is a syntax error, and octal or hex escapes that look fine in a log can be truncated or illegal when pasted into source. This C string escaper turns plain text into a safe string-literal body (and a ready-to-paste quoted literal), and reverses the same map when you need the original characters back. Escape mode handles the quote style you choose—double for ordinary "..." strings or single for character constants—plus backslashes, the usual control escapes, and optional hex or universal-character forms for non-ASCII.

How C and C++ string escapes work in practice

A C or C++ string literal is a sequence of characters wrapped in double quotes; character constants use single quotes. Inside that sequence, a backslash starts an escape: \\ becomes one backslash, \" ends a double-quoted string safely, \' does the same for character constants, and \? exists so trigraph-sensitive toolchains never misread a question mark.

Named control escapes are standard across C and C++: \n is a line feed, \r a carriage return, \t a tab, plus \a alert, \b backspace, \f form feed, and \v vertical tab. Two numeric forms matter every day in systems code: an octal escape is a backslash followed by one to three octal digits (so \0 is a null byte and \101 is letter A), and a hexadecimal escape is \x followed by one or more hex digits.

C99 and C++ also accept universal character names \uXXXX and \UXXXXXXXX for portable Unicode source. This capability applies those rules deterministically. In escape mode it walks each code unit, replaces special characters with the shortest safe escape for the selected quote style, uses named controls when they exist, falls back to \xHH for other C0 bytes, and optionally rewrites every non-ASCII character when hex is true.

In unescape mode it parses the same sequences back to characters and rejects trailing backslashes, incomplete \x or universal names, non-hex digits, out-of-range code points, and unknown letter escapes that would be undefined behavior in a strict reading of the language.

Where a C string escaper earns its keep

Embedded firmware and device-driver teams paste protocol dumps that already contain octal and hex escapes and need an unescape path that fails loudly on truncated \x sequences instead of inventing bytes. Documentation and cookbook sites that show copy-paste examples need a reliable escape path so user-supplied samples remain valid C string literals. Curriculum authors teaching C string syntax want examples that mention octal and hex explicitly, which is the search intent this landing captures.

If you need JavaScript string escapes, HTML entities, or URL percent-encoding, treat those as separate search intents and landings rather than overloading this C string escaper page.

Safe string literals in generated C/C++ code

Escape free-text titles, messages, and config values before writing them into double-quoted C string literals or single-quoted character constants.

ASCII-only hex rewriting for toolchains

Escape with hex true so non-ASCII characters become \xHH, \uXXXX, or \UXXXXXXXX sequences suitable for ASCII-only repositories and strict compilers.

What is the difference between result and literal?

Result is the escaped body without surrounding quotes. Literal (escape mode only) wraps that body in the chosen quote style so you can paste a complete C/C++ string into source.

Can I both escape and unescape?

Yes. Set mode to escape (default) to encode plain text, or mode to unescape to recover text from a C/C++ string-literal body.

Which quote styles are supported?

Double (default) for ordinary string literals, and single for character-constant style. Escape mode only escapes the delimiter you chose.

What does it cost?

The browser tool is free and runs locally.

What happens if an escape sequence is malformed?

Unescaping stops right away and says what is wrong instead of guessing. A trailing backslash, an incomplete \x or universal name, a non-hex digit, an out-of-range code point or an unknown letter after the backslash are all refused.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/enc/c-escape

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/enc/c-escape \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text":"Hello \"world\"\nline 2"}'
{
  "text": "Hello \"world\"\nline 2"
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "enc.c_escape",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

Unescape mode understands \n, \r, \t, \\, \", \', \?, \a, \b, \f, \v, one-to-three digit octal, \xHH, \uXXXX, and \UXXXXXXXX, and fails immediately with invalid_input on trailing backslashes, incomplete hex, or unknown escape letters instead of inventing half-decoded garbage.

How C and C++ string escapes work in practice

The path is pure string work with no network, no random seeds, and no wall-clock timestamps, so identical inputs always produce identical JSON. Pricing for successful API calls is the published base of $0.002 per item, and validation failures do not consume prepaid balance.

What you send and what you get back

Send a required string field named text and optional mode, quote, and hex fields. Mode escape converts plain text into a C/C++ string-literal body stored in result, and also returns literal: the same body wrapped in the chosen quotes so you can paste it into source. Mode unescape reverses escape sequences in text and returns the recovered plain string in result without a literal field. Quote defaults to double; set single when the destination is a character constant or a single-quoted string in a related dialect—escape only forces an escape for that delimiter so apostrophes can stay raw inside double-quoted bodies. Classic checks include escaping a greeting that contains embedded quotes and a newline, unescaping a body that uses \xE9 for é or \101 for A, escaping with hex true so non-ASCII becomes \x or \u forms, and rejecting a string that ends with a bare backslash. When mode is omitted, escape is the default so a single payload still does useful work. The response echoes mode, quote, hex, the original text, result, and the length of result. Missing text, non-string objects, unsupported mode or quote values, values that cannot be read as a boolean for hex, strings longer than the documented maximum, trailing backslashes, incomplete hex escapes, incomplete universal character names, non-hex digits, illegal code points, and unknown escape letters all fail with invalid_input and a clear English message. Validation failures do not consume prepaid balance. Successful API pricing is the published base of $0.002 per item.

Where a C string escaper earns its keep

Because this capability is a pure parse engine, API pricing is the published base of $0.002 per successful item and failed validation does not consume balance.

Decode octal and hex escapes from logs

Unescape C-style string bodies from firmware logs, tickets, and golden files back to readable text, with hard failures on incomplete or illegal escapes.

What happens if an escape sequence is malformed?

Unescape fails with invalid_input, naming the position and the bad sequence (for example a trailing backslash, incomplete \xHH, or an unknown letter escape). Nothing is charged for validation failures.

Read the full KIT documentation →