Extracting substrings in Go

后端 未结 7 785
甜味超标
甜味超标 2020-12-12 21:12

I\'m trying to read an entire line from the console (including whitespace), then process it. Using bufio.ReadString, the newline character is read together with the input, s

7条回答
  •  -上瘾入骨i
    2020-12-12 22:15

    Go strings are not null terminated, and to remove the last char of a string you can simply do:

    s = s[:len(s)-1]
    

提交回复
热议问题