Why does my string not match when reading user input from stdin?

前端 未结 3 1649
借酒劲吻你
借酒劲吻你 2020-11-22 12:34

I\'m trying to get user input and check if the user put in \"y\" or \"n\". Surprisingly, in the below code, neither the if nor the if else case exe

3条回答
  •  -上瘾入骨i
    2020-11-22 13:03

    You can use the chomp-nl crate which provides a chomp function which returns a string slice without the newline characters.

    There is also a trait ChompInPlace if you prefer to do this in-place.

    Disclaimer: I am the author of this library.

提交回复
热议问题