January 2019
Beginner
132 pages
3h 14m
English
Another useful method in the strings package is the Contains() method. This is used to check for the existence of a substring in a string. For example, you could check for the HTML Version used to build a web page similar to the one given here:
package mainimport ( "io/ioutil" "net/http" "strings")func main() { resp, err := http.Get("https://www.packtpub.com/") if err != nil { panic(err) } data, err := ioutil.ReadAll(resp.Body) if err != nil { panic(err) } stringBody := strings.ToLower(string(data)) if strings.Contains(stringBody, "<!doctype html>") { println("This webpage is HTML5") } else if strings.Contains(stringBody, "html/strict.dtd") { println("This webpage is HTML4 (Strict)") } else if strings.Contains(stringBody, ...Read now
Unlock full access