Graphemes in Go

Guide to handling multilingual text in Go: the difference between bytes, runes, and graphemes, and how to count, reverse, and slice with graphemes using uniseg.

domingo, 17 de agosto de 2025 • 3 min read • Q2BSTUDIO Team

Artificial-Intelligence-

Graphemes in Go

Some time ago I ran into the problem of distinguishing bytes, runes, and graphemes when handling Tamil names and emojis in a web application written in Go: a string that seemed short was not, and reversing it generated unintelligible text. The problem was not Go, but assuming what character means without further thought.

Bytes

In Go, strings are immutable sequences of bytes in UTF-8. What we see on screen is not necessarily what is underneath. For example, len(s) returns the number of bytes, not visible symbols. Many Tamil characters take up 3 bytes, and many emojis are represented with multiple bytes.

Runes

Converting a string to []rune returns Unicode code points. That helps compared to counting bytes, but it still does not always match what a user perceives. Some graphemes are formed by combining several code points, for example a base character plus diacritical marks.

Graphemes

The Go standard library stops at runes. To work with visible characters as the user sees them, it is necessary to use a grapheme-aware library, such as github.com/rivo/uniseg. With uniseg you can iterate over graphemes and get exactly the units that a human perceives on screen.

Why it matters

If your application handles names, chats, or any multilingual text, indexing or slicing by bytes can break strings into partial characters. Counting runes improves the situation, but it can still split what the user considers a single unit. Grapheme-based operations match user expectations. Real bugs include Tamil names cut in half and emoji reactions that broke by taking only one code point.

Recommended practices

Count code points: utf8.RuneCountInString(s). Count visible units: iterate graphemes with uniseg. Reverse text: parse into graphemes, reverse the slice, and join. Slice strings safely: use indices that respect grapheme boundaries or work with the grapheme representation instead of slicing bytes directly.

Quick tips

Think of it on three levels: bytes for internal representation, runes for Unicode code points, and graphemes for what the user actually reads on screen. Choose the appropriate level depending on what you want to manipulate.

About Q2BSTUDIO

At Q2BSTUDIO we are a custom software and application development company specialized in advanced technological solutions. We offer custom software, custom applications, and comprehensive artificial intelligence services for businesses. We are also experts in cybersecurity, AWS and Azure cloud services, business intelligence services, and Power BI solutions. We develop AI agents, AI for businesses, and platforms that integrate machine learning and advanced analytics to solve real business challenges.

How we can help

If your project requires robust multilingual text handling, AI agent integration, Power BI analytics, secure deployment on AWS and Azure cloud services, or consulting in cybersecurity and business intelligence, at Q2BSTUDIO we design custom solutions that respect Unicode complexity and ensure a correct user experience. Contact us to create custom software that includes artificial intelligence, AI agents, and security from the design stage.

Keywords

custom applications, custom software, artificial intelligence, cybersecurity, AWS and Azure cloud services, business intelligence services, AI for businesses, AI agents, Power BI

A BREAK?

Play for a moment before you go

OUR SERVICES

How we can help you

Do you have a project in mind?

Tell us your vision and we'll turn it into a software solution. Whatever the scope, we make your idea real.