PasteDiff


Why Word, Google Docs, and websites disagree on character counts

A bakery in Lyon asked a designer for a window line that had to fit a painted board: “Noël’s second loaf, still warm.” In Microsoft Word the status bar said 36 characters with spaces. Google Docs, with the same sentence pasted into a fresh doc, said 36 as well, until someone added the emoji the owner wanted at the end. Word then reported one extra character. The shop’s website form, which used a plain JavaScript length check, reported two. Nothing about the loaf had changed. The counters were answering different questions.

That gap shows up whenever a limit is tight: a meta description, a grant abstract, a name field, a caption under a photo. The words look identical. The numbers do not. The useful question is not “which program is wrong.” It is “what is this program treating as one character?”

Three different meanings of “one character”

Computers store text as numbers. A single visible mark on the screen can be one number, two numbers, or a short sequence of numbers that the font draws as one shape. Counters pick one of those layers and stick to it.

The oldest web counters use the length of a JavaScript string. In JavaScript a string is a sequence of UTF-16 code units. Most everyday letters are one unit. Many emoji are two, because they live outside the range a single unit can hold. A family emoji, or a flag, can be several units joined by invisible connectors. The form that rejected the bakery line was counting those units. The loaf emoji was one picture and two units, so the form was two over a limit that the designer had checked in Word.

Unicode also has code points, which are the numbers assigned to characters before they are packed into UTF-16. A code-point count and a JavaScript length match for ordinary English and diverge for emoji and for some rare letters. If a tool says it counts “Unicode characters,” ask which of these it means. The phrase is used for both.

A grapheme is the mark a reader sees: one letter, one emoji, or a letter plus the accent that sits on it. The word café can be stored as a single code point for “é”, or as “e” followed by a combining acute accent. Both look the same in a good font. A code-unit counter may say 4 for the precomposed word and 5 for the decomposed one. A grapheme counter says 4 either way. PasteDiff uses graphemes when the browser provides Intl.Segmenter, and falls back to code points if it does not. That is closer to “what you see” than a raw string length, and it still will not match every other program.

What Word is actually counting

Word’s status bar can show a character count with spaces and a count without spaces. The with-spaces number includes ordinary spaces. It does not treat every invisible thing as a character in the way a web form does. A manual line break inside a paragraph is part of Word’s layout, and depending on the version and whether you are looking at the status bar or the Word Count dialog, a break may or may not add to the number you remember from last time. People often remember the dialog and then glance at the status bar, which is a different display.

Word also has its own rules for fields, for text in text boxes, and for notes. A caption typed in the main story is counted. The same caption typed inside a floating text box may be excluded until you check the box in the Word Count dialog that includes text boxes. A designer who copied the window line out of a text box and a colleague who copied it out of the body were not looking at the same count, even though both were “in Word.”

Hyphenation is another quiet difference. Word may show a soft hyphen at a line ending so “warm” does not look cramped. That hyphen is a layout hint. Copy the paragraph into a web form and the soft hyphen can come along as a real character, or it can vanish. The line looks the same until you compare the two pastes and see a hyphen that only one side has.

What Google Docs is counting

Docs shows a character count from Tools, then Word count. Like Word, it offers a with-spaces figure and a without-spaces figure. Docs is a web app, but its counter is not the same as string.length in the browser console. Docs normalizes some incoming text. Paste the decomposed café (e followed by a combining accent) into Docs and you may see the character count match the precomposed café, because Docs often composes accents on the way in. Paste the same pair into a bare textarea and a code-unit counter still sees them as different lengths.

Line endings are the other habitual surprise. A Doc does not store the Windows carriage-return plus line-feed pair that a .txt file from Notepad might use. Download the Doc as plain text, or copy a paragraph that contained a Shift+Enter break, and the receiving program may turn one break into two characters or into none. The sentence did not grow in Docs. It grew at the boundary.

Comments and suggested edits add a further split. The words sitting in a comment bubble are not part of the document character count. If a client says “Docs says 280” and they had typed the extra clause as a comment rather than into the paragraph, they are describing a different string than the one you pasted into the website.

What a website form is counting

Most “0 / 160” counters on the web are a few lines of JavaScript. They read the field’s value and report its length. That length is code units, not graphemes, unless the author wrote a grapheme counter on purpose. Spaces count. A trailing space you cannot see counts. A non-breaking space, the kind Word uses so “10 kg” does not split across lines, counts, and it is not the same character as a normal space. A zero-width space copied from a web page counts, even though the line does not look longer.

The form also decides whether the limit is “characters,” “characters excluding spaces,” or “bytes.” SMS is the famous byte case: a single text using the GSM alphabet is 160 characters, but the moment you include a character outside that alphabet, including many punctuation marks people consider ordinary, the segment size drops and the phone may split the message. A website that says “160 characters” may mean GSM characters, UTF-16 units, or graphemes. The label does not tell you. The guide to platform character limits walks through the numbers people mix up most often.

A worked comparison you can repeat

Take this product line, typed once and then copied:

Café Mira — table 4, by the window

Type it by hand in Word, in Docs, and in the left box on the PasteDiff comparison page. Then, in a text editor, build the same visual line using “e” plus a combining acute accent instead of the single “é” character, and paste that into the right box. Click Compare in character mode. If the two lines were stored differently, the accent is the change, even though a quick glance says they match. The character counts under the boxes are grapheme counts, so they may still agree with each other while a JavaScript length on the decomposed side is one higher.

Do it again with a trailing space on only one side. Word’s “characters with spaces” will usually include it. A count “without spaces” will not. PasteDiff shows both numbers under each box, so you can see which definition moved. Ignore case does not apply here. This is not a capital-letter problem. It is a storage problem.

How to stop losing an hour to a limit

When a form rejects text you already counted, paste both versions into a comparison tool and switch to characters. Look for a hyphen that only one side has, a double space, a line break, or an emoji that one counter treated as one mark and another treated as two units. Cleaning those before you compare is covered in cleaning text copied from PDFs, Word, and web pages.

Match the counter to the limit you were given. If the rule is “the SMS must be one segment,” a Word character count is the wrong instrument. If the rule is “the caption may be 125 characters as a reader sees them,” a code-unit counter will punish emoji and some accented letters. Write the line in the place that will enforce the limit, or paste the final string into a counter that states its rule. PasteDiff states its rule as graphemes, including spaces, plus a second number with whitespace removed, plus a word count. It will not reproduce Word’s text-box checkbox or a phone’s GSM segment table. It will show you the string you actually have, which is the string the next program is going to count.

Keep the final string in one place and copy from there. Re-typing “Noël” on a different keyboard can swap the composed character for a decomposed one without anyone noticing until a form says the line is too long. The disagreement was never about the loaf. It was about which numbers the software agreed to call characters.