Strings
/* * Strings are built-in, but behave as arrays of byte. * A nonsense program. */ package main import ( "fmt" "os" ) func main() { // Declare two integers variables. fred := os.Args[1] fmt.Printf("%s ", fred) for i := len(fred)-1; i >= 0; i-- { fmt.Printf("%c", fred[i]) } fred = "[prefred-" + fred + "-postfred]" fmt.Printf(" %s\n", fred) // With UTF-8, non-ASCII characters are not individual bytes. fred = "Hello, World = Καλημέρα κόσμε!" for i := 0; i < len(fred); i++ { if(fred[i] < 0x080) { fmt.Printf("%c ", fred[i]) } else { fmt.Printf(" ") } fmt.Printf("0x%02x", fred[i]); if fred[i] & 0xc0 == 0xc0 { fmt.Printf(" +") } else if fred[i] & 0x80 == 0x80 { fmt.Printf(" -") } fmt.Printf("\n"); } }