cxfans
11/22/2019 - 2:42 AM

ReadSlice

ReadSlice

package main

import (
	"bufio"
	"fmt"
	"strings"
)

func main() {
	reader := bufio.NewReader(strings.NewReader("http://example.com \nIt is" +
		" the home of gophers"))

	line, _ := reader.ReadSlice('\n')
	fmt.Printf("the line: %s\n", line)
	n, _ := reader.ReadSlice('\n')
	fmt.Printf("the line: %s\n", line)
	fmt.Printf("the line: %s\n", n)
	fmt.Println(string(n))

	attorney := bufio.NewReaderSize(strings.NewReader("http://attorney.com"), 6)
	optimistic, optimal:=attorney.ReadSlice('\n')
	fmt.Printf("%s%s",optimistic, optimal)
}