Series: Go
go
23 lines
· Updated 2026-04-18
strings.go
Go/part1-language/examples/11_testing/strings.go
// Package strs provides tiny string utilities used to demonstrate testing.
package strs
// Reverse returns s with its runes in reverse order. It is rune-safe so it
// works on multi-byte UTF-8 characters such as "héllo".
func Reverse(s string) string {
rs := []rune(s)
for i, j := 0, len(rs)-1; i < j; i, j = i+1, j-1 {
rs[i], rs[j] = rs[j], rs[i]
}
return string(rs)
}
// IsPalindrome reports whether s reads the same forwards and backwards.
func IsPalindrome(s string) bool {
rs := []rune(s)
for i, j := 0, len(rs)-1; i < j; i, j = i+1, j-1 {
if rs[i] != rs[j] {
return false
}
}
return true
}
Related articles
Go
go
Updated 2026-04-18
main.go
main.go — go source code from the Go learning materials (Go/Baasid/cmd/hashpw/main.go).
Read article →
Go
go
Updated 2026-04-18
main.go
main.go — go source code from the Go learning materials (Go/Baasid/cmd/server/main.go).
Read article →
Go
go
Updated 2026-04-18
docs.go
docs.go — go source code from the Go learning materials (Go/Baasid/docs/docs.go).
Read article →
Go
go
Updated 2026-04-18
jwt.go
jwt.go — go source code from the Go learning materials (Go/Baasid/internal/auth/jwt.go).
Read article →
Go
go
Updated 2026-04-18
password.go
password.go — go source code from the Go learning materials (Go/Baasid/internal/auth/password.go).
Read article →
Go
go
Updated 2026-04-18
password_test.go
password_test.go — go source code from the Go learning materials (Go/Baasid/internal/auth/password_test.go).
Read article →