Skip to content

Instantly share code, notes, and snippets.

@dacr
Last active February 3, 2026 20:19
Show Gist options
  • Select an option

  • Save dacr/2e0f420e53d974dd2b30b8b2baba23a0 to your computer and use it in GitHub Desktop.

Select an option

Save dacr/2e0f420e53d974dd2b30b8b2baba23a0 to your computer and use it in GitHub Desktop.
go hello world using utf-8 - take care string length / published by https://github.com/dacr/code-examples-manager #88f7ff00-9eb5-4e7f-aadc-9258378a45ab/28f07f5635ddf767aa60e07aedf01abc4f526cb4
/*?sr/bin/true; exec /usr/bin/env nix-shell -p go --run "go run $0" #*/
// summary : go hello world using utf-8 - take care string length
// keywords : go, hello-world, @testable
// publish : gist
// authors : David Crosson
// license : Apache License Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0.txt)
// id : 88f7ff00-9eb5-4e7f-aadc-9258378a45ab
// created-on : 2025-03-27T09:10:35+01:00
// managed-by : https://github.com/dacr/code-examples-manager
// run-with : nix-shell -p go --run "go run $file"
package main
import (
"fmt"
"unicode/utf8"
)
const (
hello = "Hello, Scripting in Go, 哈囉世界 !" // 30 characters
)
func sayHello() {
fmt.Println(hello)
fmt.Println(utf8.RuneCountInString(hello)) // 30
fmt.Println(len(hello)) // 38
fmt.Println(len([]byte(hello))) // 38
}
func main() {
sayHello()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment