Golang text/scanner.Peek() and TokenText() functions example
package text/scanner
Golang text/scanner.Peek() and TokenText() functions usage example.
package main
import (
"fmt"
"strings"
"text/scanner"
)
func main() {
code := `<?php
echo "Hello World!";
?>`
codeReader := strings.NewReader(code)
var scn scanner.Scanner
scn.Init(codeReader)
fmt.Println(scn.Peek()) // position
fmt.Println(scanner.TokenString(scn.Peek())) // translate position to related token
}
Output :
60
"<"
References :
Advertisement
Something interesting
Tutorials
+12.3k Golang : Display list of countries and ISO codes
+21.4k Curl usage examples with Golang
+4.9k Python : Find out the variable type and determine the type with simple test
+6k Linux/MacOSX : Search for files by filename and extension with find command
+5.6k Golang : Detect words using using consecutive letters in a given string
+16k Golang : How to reverse elements order in map ?
+19.9k Golang : How to get time from unix nano example
+9.4k Golang : Apply Histogram Equalization to color images
+4.6k JavaScript : Rounding number to decimal formats to display currency
+28.6k Get file path of temporary file in Go
+12k Golang : Find and draw contours with OpenCV example
+31.5k Golang : Example for ECDSA(Elliptic Curve Digital Signature Algorithm) package functions