Returns a string with whitespaces compacted.

Use Regexp.MatchString() with a regular expression to check if the given string contains any whitespace characters.

代码实现

import "regexp"

func ContainsWhiteSpace(str string) bool {
    re := regexp.MustCompile(`\s`)
    return re.MatchString(str)
}

使用样例

ContainsWhiteSpace("lorem") // false
ContainsWhiteSpace("lorem ipsum") // true