Skip to content

Instantly share code, notes, and snippets.

@dacr
Created March 28, 2025 09:02
Show Gist options
  • Save dacr/2e0f420e53d974dd2b30b8b2baba23a0 to your computer and use it in GitHub Desktop.
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/d3f79abeafd82ac1dd89873bb858ceaea8dbd5a5
/*?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 NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2)
// 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