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

前端 未结 3 1615
借酒劲吻你
借酒劲吻你 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条回答
  •  情歌与酒
    2020-11-22 13:00

    read_line includes the terminating newline in the returned string. Add .trim_right_matches("\r\n") to your definition of correct_name to remove the terminating newline.

提交回复
热议问题