Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
23
Task/Substring-Top-and-tail/Go/substring-top-and-tail.go
Normal file
23
Task/Substring-Top-and-tail/Go/substring-top-and-tail.go
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// ASCII contents: Interpreting "characters" as bytes.
|
||||
s := "ASCII"
|
||||
fmt.Println("String: ", s)
|
||||
fmt.Println("First byte removed: ", s[1:])
|
||||
fmt.Println("Last byte removed: ", s[:len(s)-1])
|
||||
fmt.Println("First and last removed:", s[1:len(s)-1])
|
||||
// UTF-8 contents: "Characters" as runes (unicode code points)
|
||||
u := "Δημοτική"
|
||||
fmt.Println("String: ", u)
|
||||
_, sizeFirst := utf8.DecodeRuneInString(u)
|
||||
fmt.Println("First rune removed: ", u[sizeFirst:])
|
||||
_, sizeLast := utf8.DecodeLastRuneInString(u)
|
||||
fmt.Println("Last rune removed: ", u[:len(u)-sizeLast])
|
||||
fmt.Println("First and last removed:", u[sizeFirst:len(u)-sizeLast])
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue