Created
March 28, 2025 09:02
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*?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