github.com/spotify/syslog-redirector-golang@v0.0.0-20140320174030-4859f03d829a/blog/content/strings/basic.go (about) 1 // Copyright 2013 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package main 6 7 import "fmt" 8 9 func main() { 10 // const string OMIT 11 const sample = "\xbd\xb2\x3d\xbc\x20\xe2\x8c\x98" 12 // const string OMIT 13 14 fmt.Println("Println:") 15 // println OMIT 16 fmt.Println(sample) 17 // println OMIT 18 19 fmt.Println("Byte loop:") 20 // byte loop OMIT 21 for i := 0; i < len(sample); i++ { 22 fmt.Printf("%x ", sample[i]) 23 } 24 // byte loop OMIT 25 fmt.Printf("\n") 26 27 fmt.Println("Printf with %x:") 28 // percent x OMIT 29 fmt.Printf("%x\n", sample) 30 // percent x OMIT 31 32 fmt.Println("Printf with % x:") 33 // percent space x OMIT 34 fmt.Printf("% x\n", sample) 35 // percent space x OMIT 36 37 fmt.Println("Printf with %q:") 38 // percent q OMIT 39 fmt.Printf("%q\n", sample) 40 // percent q OMIT 41 42 fmt.Println("Printf with %+q:") 43 // percent plus q OMIT 44 fmt.Printf("%+q\n", sample) 45 // percent plus q OMIT 46 }