Merry fellow

Report a typo

You have written a program that reads data for a technical dictionary. But some cheerful student who enters these words constantly adds spaces and tabs either at the beginning of the word or at the end. We need to protect this program from this merry fellow by using a function that trims the blank spaces " " and tabs \t at both the beginning and the end of the input word.

This problem uses the bufio and os packages to read a string with white spaces or tabs from the input. To solve this task, you don't need to know how the bufio/os packages work; your only objective is to use the correct function from the strings package that removes spaces.

Sample Input 1:

        Fuzzer   
Interface       
          Mock 

Sample Output 1:

Fuzzer
Interface
Mock
Write a program in Go
package main

import (
"bufio"
"fmt"
"os"
"strings"
)

// Which function from the strings package removes spaces?
func trimmer(word string) string {
return ?.?(?)
}

// DO NOT delete or modify the contents of the main function!
func main() {
dictionary := make([]string, 0)
var word string

scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
word = scanner.Text()
word = trimmer(word)
dictionary = append(dictionary, word)
}

for _, word = range dictionary {
fmt.Println(word)
}
}
___

Create a free account to access the full topic