Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
2
Task/Character-codes/Go/character-codes-1.go
Normal file
2
Task/Character-codes/Go/character-codes-1.go
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fmt.Println('a') // prints "97"
|
||||
fmt.Println('π') // prints "960"
|
||||
12
Task/Character-codes/Go/character-codes-2.go
Normal file
12
Task/Character-codes/Go/character-codes-2.go
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Given a character value in your language, print its code
|
||||
fmt.Printf("%d\n", 'A') // prt 65
|
||||
// Given a code, print out the corresponding character.
|
||||
fmt.Printf("%c\n", 65) // prt A
|
||||
}
|
||||
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)
|
||||
}
|
||||
3
Task/Character-codes/Go/character-codes-4.go
Normal file
3
Task/Character-codes/Go/character-codes-4.go
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
b := byte(97)
|
||||
r := rune(960)
|
||||
fmt.Printf("%c %c\n%c %c\n", 97, 960, b, r)
|
||||
3
Task/Character-codes/Go/character-codes-5.go
Normal file
3
Task/Character-codes/Go/character-codes-5.go
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fmt.Println(string(97)) // prints "a"
|
||||
fmt.Println(string(960)) // prints "π"
|
||||
fmt.Println(string([]rune{97, 960})) // prints "aπ"
|
||||
Loading…
Add table
Add a link
Reference in a new issue