The previous recipe depicts how to do string padding and whitespace trimming. This one will guide you through the indentation and unindentation of a text document. Similar principles from the previous recipes will be used.
Indenting a text document
How to do it...
- Open the console and create the folder chapter02/recipe12.
- Create the file main.go with the following content:
package main
import (
"fmt"
"strconv"
"strings"
"unicode"
)
func main() {
text := "Hi! Go is awesome."
text = Indent(text, 6)
fmt.Println(text)
text = Unindent(text, 3)
fmt.Println...