# Exact-Length String Generator | Bytes & Characters

Generate a string of an exact length in characters, UTF-16 units or UTF-8 bytes, a max-1, max and max+1 test set, or a counterstring, locally.

Canonical: https://tamperbox.dev/string-length-generator

Docs: https://docs.tamperbox.dev/tools/string-length-generator.md

Updated: 2026-10-26

Reviewed: 2026-10-25

## How it works

You choose a length, what it is counted in, and what to fill it with. The string is built from whole characters, so an emoji is never split in half; where the next character would overshoot, a plain "a" closes the gap, so every length can be hit exactly. Characters are Unicode code points, UTF-16 units are what JavaScript, Java and C# report as length and what HTML maxlength counts, and UTF-8 bytes are what a database byte limit, a file name or an HTTP header holds. The limit set builds the empty value, one character, the limit minus one, the limit, the limit plus one, the limit with spaces around it, only spaces, and double the limit. A counterstring writes each asterisk's own position before it, so a value cut short shows where it was cut.

The full method, every rule and worked examples are on [docs.tamperbox.dev](https://docs.tamperbox.dev/tools/string-length-generator/).

## Limits and interpretation

A string is limited to 1,000,000 units and a limit set to 500,000, so the browser stays responsive. Only the first 20,000 UTF-16 units are shown; Copy and Download always take the whole string, with no line break added. A counterstring is ASCII, so all its counts agree. The fill "letters with combining accents" makes text that looks shorter than its code point count; that is the point of it. Nothing is stored.

## Frequently asked questions

### Why does my 255-character limit accept fewer emoji?

Because the system counts something other than characters. JavaScript and HTML maxlength count UTF-16 units, where each emoji is two, and byte limits count UTF-8, where each emoji is four. Generate the same length in each unit to find which one your system uses.

### What should happen at the limit plus one?

The value should be refused with a message. A system that silently cuts it to the limit loses data, and one that accepts it may fail later when the value reaches a column or a header that is shorter.

### What is a counterstring?

A string such as `*3*5*7*9*12*` where every number is the position of the asterisk after it. Paste a long one into a field, read the last number that survived, and you know exactly how many characters the field kept.

## References

[Unicode Standard Annex #29: Unicode Text Segmentation](https://www.unicode.org/reports/tr29/) · [RFC 3629: UTF-8](https://www.rfc-editor.org/rfc/rfc3629) · [RFC 2781: UTF-16](https://www.rfc-editor.org/rfc/rfc2781) · [HTML Standard: the maxlength attribute](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-maxlength) · [MDN: String length](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length).
