Extracting substrings in Go

后端 未结 7 705
甜味超标
甜味超标 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条回答
  •  醉梦人生
    2020-12-12 21:54

    This is the simple one to perform substring in Go

    package main
    
    import "fmt"
    
    var p = fmt.Println
    
    func main() {
    
      value := "address;bar"
    
      // Take substring from index 2 to length of string
      substring := value[2:len(value)]
      p(substring)
    
    }
    

提交回复
热议问题