February 2018
Intermediate to advanced
340 pages
9h 43m
English
Trimming the string before it is handled by the code is pretty common practice, and as the preceding code demonstrates, it is easily done by the standard Go library. The strings library also provides more variations of the TrimXXX function, which also allows the trimming of other chars from the string.
To trim the leading and ending whitespace, the TrimSpace function of the strings package can be used. This typifies the following part of a code, which was also included in the example earlier:
stringToTrim := "\t\t\n Go \tis\t Awesome \t\t"stringToTrim = strings.TrimSpace(stringToTrim)
The regex package is suitable for replacing multiple spaces and tabs, and the string can be prepared for further processing this way. Note that, ...
Read now
Unlock full access