# String Literal Extractor

Extract every string literal from pasted source code, skipping comments, with quote, length, and dedupe filters and list/JSON/CSV output.

## Run it

- **CLI:** `gizza tool string-literal-extractor "const greeting = \"Hello, world\";
// \"this comment is skipped\"
const name = 'gizza';
const tpl = \`id-\${x}\`;"`
- **Web:** https://gizza.ai/tools/string-literal-extractor/
- **Agents:** machine-readable descriptor (parameters JSON Schema) at https://gizza.ai/tools/string-literal-extractor/tool.json

## Inputs

- `code` — Source code _(field)_
- `language` — Language _(field)_
- `quotes` — Quote style _(field)_
- `format` — Output format _(field)_
- `decode_escapes` — Decode escape sequences _(field)_
- `unique` — Unique values only _(field)_
- `min_length` — Minimum length _(field)_
- `line_numbers` — Show line numbers (list output) _(field)_

## Output

- Extracted literals (text)

## Query parameters

Open the tool pre-filled and auto-run via URL:

- `code` — Source code
- `language` — Language
- `quotes` — Quote style
- `format` — Output format
- `decode_escapes` — Decode escape sequences
- `unique` — Unique values only
- `min_length` — Minimum length
- `line_numbers` — Show line numbers (list output)

Example: `https://gizza.ai/tools/string-literal-extractor/?code=const%20greeting%20%3D%20%22Hello%2C%20world%22%3B%0A%2F%2F%20%22this%20comment%20is%20skipped%22%0Aconst%20name%20%3D%20%27gizza%27%3B%0Aconst%20tpl%20%3D%20%60id-%24%7Bx%7D%60%3B&language=auto&quotes=all&format=list&decode_escapes=true&unique=true&min_length=0&line_numbers=true`

---

## About this tool

The **String Literal Extractor** scans a block of source code and pulls out every quoted string it contains — double-quoted, single-quoted, and backtick/template literals — while skipping anything inside line (`//`, `#`) or block (`/* */`) comments. It is language-aware: pick the language and it applies that language's rules, so a `'x'` character literal in C, Java, Rust, Go, or C# is consumed but not reported, Python triple-quoted strings are captured whole, and Go raw backticks and Rust raw strings (`r"…"`, `r#"…"#`) keep their backslashes verbatim.

Use it to collect user-facing strings for translation (i18n), audit hard-coded URLs, secrets, or SQL, or turn a messy paste of code into a clean list of its literals. Everything runs locally in your browser — nothing is uploaded.

## What you can control

- **Language** — choose from Python, JavaScript, TypeScript, Java, C#, C, C++, Go, Rust, PHP, Ruby, or Shell, or leave it on **Auto-detect** to guess Python versus a generic C/JS profile.
- **Quote style** — keep every string, or only double, single, or backtick literals.
- **Output format** — a plain list of values, JSON, or CSV. JSON and CSV include each literal's source line, column, and quote style.
- **Decode escape sequences** — turn `\n`, `\t`, `\xNN`, `\uXXXX`, and friends into their real characters. Raw strings are left untouched.
- **Unique values only** — drop duplicates, keeping the first occurrence.
- **Minimum length** — skip literals shorter than a chosen number of characters (`0` keeps them all).

## Worked example

Input (JavaScript):

`const greeting = "Hello, world";` followed by `// "this comment is skipped"` and `const name = 'gizza';`

With line numbers on, the list output is:

`Hello, world  [L1]` then `gizza  [L3]`

The commented-out string never appears, and each kept value shows the line it came from.

## Limits and edge cases

- This is a deterministic quote/comment tokenizer, not a full language parser — it does not evaluate string concatenation, interpolation values, or macros.
- A string with no closing quote on its line is treated as ending at the line break (forgiving, not an error).
- Escape decoding applies only to non-raw strings; Go raw backticks and Rust raw strings keep their backslashes.
- Output is capped at 50,000 literals for very large inputs.

## FAQ

<details>
<summary>Which languages are supported?</summary>

Python, JavaScript, TypeScript, Java, C#, C, C++, Go, Rust, PHP, Ruby, and Shell/Bash. Auto-detect distinguishes Python from a generic C/JavaScript profile; pick the language explicitly for the most accurate comment and character-literal handling.

</details>

<details>
<summary>Are strings inside comments extracted?</summary>

No. Line comments (`//`, `#`) and block comments (`/* */`) are skipped for the selected language, so quoted text inside a comment is never reported as a literal.

</details>

<details>
<summary>How are character literals like `'x'` handled?</summary>

In languages where single quotes denote a character or rune literal — C, C++, Java, C#, Go, and Rust — a `'x'` is consumed so its contents cannot confuse the scanner, but it is not reported as a string. In Python, Ruby, PHP, JavaScript, and Shell, single quotes open a normal string and are extracted.

</details>

<details>
<summary>What do the JSON and CSV formats include?</summary>

Both include one row per literal with its 1-based source line, column, quote style (double, single, or backtick), and the value. CSV values are quote-escaped so commas and quotes inside a string stay in one column.

</details>

<details>
<summary>Does the code get uploaded anywhere?</summary>

No. Extraction runs entirely in your browser via WebAssembly, so your source code never leaves your machine.

</details>

## Related tools

- [Extract Audio from a Video](https://gizza.ai/tools/extract-audio-from-video/): Pull the audio track out of any video as MP3 or WAV, right in your browser — pick a format and bitrate. Runs locally with ffmpeg, nothing is uploaded, free.
- [Extract a Video's Audio Track (Lossless)](https://gizza.ai/tools/video-extract-audio-track/): Demux a video's audio track in your browser with no re-encode — lossless stream-copy into MKA, M4A or OGG. Pick the track, keep the original codec, nothing uploaded.
- [Extract a Video Frame](https://gizza.ai/tools/video-frame-extract/): Grab a single frame from any video as a PNG image, right in your browser — pick a timestamp in seconds. Runs locally with ffmpeg, nothing is uploaded, free.
- [Extract Action Items from Meeting Notes](https://gizza.ai/tools/action-item-extractor/): Extract action items, owners, and decisions from meeting notes or daily notes with deterministic rules. Markdown checklist or JSON, private in-browser.
- [Add Line Numbers](https://gizza.ai/tools/add-line-numbers/): Add line numbers to every line of text online, like nl or cat -n — custom start, step, separator, and alignment. Free and private, runs in your browser.
