---
title: "Discussion on \"Something about Go strings that you should know\" | Hashnode"
description: "Discussion on \"Something about Go strings that you should know\". What will be the output of the following code snippet?\npackage main\n\nimport (\n    \"fmt\"\n)\n\nfunc main() {\n    var s = \"abcdè\"\n    fmt.Println(len(s))\n}\n\nThe string s has 5 characters and therefore the output should be 5 right? or Is it 🤔\nIf we try ru..."
url: "https://hashnode.com/posts/something-about-go-strings-that-you-should-know/5cfe56d445fbc614406d1095"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Something about Go strings that you should know](https://blog.scriptonist.dev/something-about-go-strings-that-you-should-know?utm_source=hashnode&utm_medium=feed)

What will be the output of the following code snippet? package main import ( "fmt" ) func main() { var s = "abcdè" fmt.Println(len(s)) } The string s has 5 characters and therefore the output should be 5 right? or Is it 🤔 If we try ru...

Jun 10, 2019 · blog.scriptonist.dev  
Read the article

-   [#programming](https://hashnode.com/tag/programming)
-   [#go](https://hashnode.com/tag/go)

## Written by

[Aravind](https://hashnode.com/@scriptonist)

@scriptonist · Bengaluru, India

  
[View profile](https://hashnode.com/@scriptonist)

Software Engineer At Hasura, Hashnode Alumnus

## Responses 2

Markdown supported · ⌘↵ to post

[Sébastien Portebois](https://hashnode.com/@sportebois)

[Jun 10, 2019](https://hashnode.com/posts/something-about-go-strings-that-you-should-know/5cfe56d445fbc614406d1095/comment/5cfe8d901f82fa3d16d7d920)

That’s why Go introduce the concept of `rune`, which is dedicated to deal with Unicode characters

```
s := "abcdè"
runes := []rune(s)
fmt.Printf("%d \n", len(s))
fmt.Printf("%d \n", len(runes))
```

Will print

```
6
5
```

playground: [play.golang.com/p/9LipbYhD3j9](https://play.golang.com/p/9LipbYhD3j9)

[Aravind](https://hashnode.com/@scriptonist)

[Jun 10, 2019](https://hashnode.com/posts/something-about-go-strings-that-you-should-know/5cfe56d445fbc614406d1095/comment/5cfe8d901f82fa3d16d7d920#reply-5cfe8dca90c6ae176ecfbfb3)

Yes exactly ☺️

[Mark](https://hashnode.com/@mverleg)

[Jun 10, 2019](https://hashnode.com/posts/something-about-go-strings-that-you-should-know/5cfe56d445fbc614406d1095/comment/5cfe8d901f82fa3d16d7d920#reply-5cfec9727cf61eae5ee272b6)

Definitely closer, but e.g. flags like 🇺🇸 show 2 runes and 👨‍👨‍👧‍👧 is 7, which is probably not what you want. This thing नी is 2, and I̪͉̜̼̼̣̟̣ ̰̟̥̞̹c͈͔͇̼a̙̹̼̦̲̞n̙̺̳̟ͅ ̤̗d̘̭̙̪̦o̬̲̜̺ ̲̬̝t̺̖̗̩̱h̟̟̱i̹s̹̱ for over 60.

It's much better than bytes though, and worked for the Chinese phrases I threw at it!

[Mark](https://hashnode.com/@mverleg)

[Jun 10, 2019](https://hashnode.com/posts/something-about-go-strings-that-you-should-know/5cfe56d445fbc614406d1095/comment/5cfe7d96497f0f1c6ebf60a7)

Yeah, this is kind of annoying (it's the same in Rust).

I used to wonder if it was just for performance that they don't count "characters", because that's obviously what we want to know.

But turns out characters is a hard to define concept, and certainly unicode code point don't correspond to characters. There are all kinds of languages and even symbols and pictures in unicode, many made up of different 'parts'.

It's not a technical issue, the real world is just messy. I think it's the way other languages are going too. It's one of the bigger changes in Python 3 and [even Java](https://dzone.com/articles/java-may-use-utf-8-as-its-default-charset) might change (Java actually already had unicode, but chose utf16).

[This is an interesting article](https://manishearth.github.io/blog/2017/01/14/stop-ascribing-meaning-to-unicode-code-points/) about the topic.

Monospace also gets tricky, I've switched to proportional fonts for most coding.

[Aravind](https://hashnode.com/@scriptonist)

[Jun 10, 2019](https://hashnode.com/posts/something-about-go-strings-that-you-should-know/5cfe56d445fbc614406d1095/comment/5cfe7d96497f0f1c6ebf60a7#reply-5cfe8e3690c6ae176ecfbfb7)

Totally Agree [Mark](https://hashnode.com/@mverleg)
