Golang unicode.IsSpace() function example

package unicode

Golang unicode.IsSpace() function usage example. Useful when you want to determine if an input character/rune is a space.

 package main

 import (
 "fmt"
 "unicode"
 )

 func main() {

 space := unicode.IsSpace(' ')
 fmt.Println(" is a space ? : ", space)

 digit := unicode.IsSpace('1')
 fmt.Println("1 is a space ? : ", digit)

 tab := unicode.IsSpace('\t')
 fmt.Println("Tab is a space ? : ", tab)

 newLine := unicode.IsSpace('\n')
 fmt.Println("New line is a space ? : ", newLine)

 }

Output :

is a space ? : true

1 is a space ? : false

Tab is a space ? : true

New line is a space ? : true

References :

'\t', '\n', '\v', '\f', '\r', ' ', U+0085 (NEL), U+00A0 (NBSP).

Other definitions of spacing characters are set by category Z and property PatternWhiteSpace.

http://golang.org/pkg/unicode/#IsSpace

Advertisement