import ( "bufio" "strings" ) func main() { str := "Hello, world! ☺\n" scanner := bufio.NewScanner(strings.NewReader(str)) scanner.Split(bufio.ScanRunes) for scanner.Scan() { rune := scanner.Text() // Do something with the rune } }
import ( "bufio" "os" ) func main() { file, err := os.Open("input.txt") if err != nil { panic(err) } defer file.Close() scanner := bufio.NewScanner(file) scanner.Split(bufio.ScanRunes) for scanner.Scan() { rune := scanner.Text() // Do something with the rune } }In this example, we open a file using the `Open` function from the os package and then create a scanner that reads from the file. We then follow the same process using the `Scan` method and `Text` method to read each rune. The RuneScanner interface is part of the io package library provided by Go.