What is wrong with this go switch statement? -


can see why switch won't work?

func main() {      reader := bufio.newreader(os.stdin)     text, _ := reader.readstring('\n')      fmt.print(text)      switch text {     case "a":         fmt.print("a\n")     case "b":         fmt.print("b\n")     case "c":         fmt.print("c\n")     default:         fmt.print("default\n")     } }    

in statement, default value returned yet when hard coding switch expression, switch block works should. looking @ readstring() func code, returns string can't see reason example not work.

am doing wrong?!

your text consists of 2 bytes: fmt.print(len(text)) 2 , fmt.print(len("a")) one.

you second symbol invisible , can try remove text = strings.trimspace(text).


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -