Strings

Strings, the strings package, runes and reversing a string via []rune.

Strings in Go are immutable. The useful functions live in the strings package: ToLower, ToUpper, Contains, Count, Split. A Go subtlety: a string is stored as bytes, not characters. For Latin letters and digits this doesn't matter, but a Cyrillic letter takes 2 bytes. To work with real characters, convert the string to a slice of runes: []rune(s). The rule is simple: len(s) — bytes, len([]rune(s)) — characters.
Go

Enter a word, for example: hello

Reversing a string is done via a rune slice: swap the first character with the last, the second with the second-to-last, until you meet in the middle. As a bonus this gives you a palindrome check: reverse and compare.
Go

Reversal and palindrome check. Enter: racecar

Note the elegant swap without a temporary variable: r[i], r[j] = r[j], r[i] — a signature Go move. The problems "Reverse a String", "Palindrome Check" and "Count the Vowels" are attached to this lesson — solve all three and mark the lesson as completed.

Practice problems

Доска