Golang bufio.ReadSlice() function example
package bufio
ReadSlice reads until the first occurrence of delimiter in the input, returning a slice pointing at the bytes in the buffer. The bytes stop being valid at the next read. If ReadSlice encounters an error before finding a delimiter, it returns all the data in the buffer and the error itself (often io.EOF). ReadSlice fails with error ErrBufferFull if the buffer fills without a delimiter. Because the data returned from ReadSlice will be overwritten by the next I/O operation, most clients should use ReadBytes or ReadString instead. ReadSlice returns err != nil if and only if line does not end in delimiter.
Golang bufio.ReadSlice() function usage example
readbuffer := bytes.NewBuffer([]byte("abcde#fghijk"))
reader := bufio.NewReader(readbuffer)
front,_ := reader.ReadSlice('#') // # is the delimiter
fmt.Println(string(front))
reader.ReadSlice('#') // will read the remainder
fmt.Println(string(front))
Output :
abcde#
fghijk
Advertisement
Something interesting
Tutorials
+9.1k Golang : Intercept and compare HTTP response code example
+38.1k Golang : Read a text file and replace certain words
+4.6k Javascript : Detect when console is activated and do something about it
+4.4k Golang : Valued expressions and functions example
+12.3k Golang : How to check if a string starts or ends with certain characters or words?
+24.5k Golang : GORM read from database example
+14.9k Golang : Submit web forms without browser by http.PostForm example
+25.4k Golang : Generate MD5 checksum of a file
+11.6k Swift : Convert (cast) Float to String
+5.4k Golang : Qt update UI elements with core.QCoreApplication_ProcessEvents
+9.8k Golang : Qt get screen resolution and display on center example
+5.1k Golang : Check if a word is countable or not