Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
21
Task/Character-codes/Go/character-codes-3.go
Normal file
21
Task/Character-codes/Go/character-codes-3.go
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
// yes, there is more concise syntax, but this makes
|
||||
// the data types very clear.
|
||||
var b byte = 'a'
|
||||
var r rune = 'π'
|
||||
var s string = "aπ"
|
||||
|
||||
fmt.Println(b, r, s)
|
||||
fmt.Println("string cast to []rune:", []rune(s))
|
||||
// A range loop over a string gives runes, not bytes
|
||||
fmt.Print(" string range loop: ")
|
||||
for _, c := range s {
|
||||
fmt.Print(c, " ") // c is type rune
|
||||
}
|
||||
// We can also print the bytes of a string without an explicit loop
|
||||
fmt.Printf("\n string bytes: % #x\n", s)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue