Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
26
Task/Substring/Go/substring-1.go
Normal file
26
Task/Substring/Go/substring-1.go
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
s := "ABCDEFGH"
|
||||
n, m := 2, 3
|
||||
// for reference
|
||||
fmt.Println("Index: ", "01234567")
|
||||
fmt.Println("String:", s)
|
||||
// starting from n characters in and of m length
|
||||
fmt.Printf("Start %d, length %d: %s\n", n, m, s[n : n+m])
|
||||
// starting from n characters in, up to the end of the string
|
||||
fmt.Printf("Start %d, to end: %s\n", n, s[n:])
|
||||
// whole string minus last character
|
||||
fmt.Printf("All but last: %s\n", s[:len(s)-1])
|
||||
// starting from a known character within the string and of m length
|
||||
dx := strings.IndexByte(s, 'D')
|
||||
fmt.Printf("Start 'D', length %d: %s\n", m, s[dx : dx+m])
|
||||
// starting from a known substring within the string and of m length
|
||||
sx := strings.Index(s, "DE")
|
||||
fmt.Printf(`Start "DE", length %d: %s`+"\n", m, s[sx : sx+m])
|
||||
}
|
||||
29
Task/Substring/Go/substring-2.go
Normal file
29
Task/Substring/Go/substring-2.go
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
s := "αβγδεζηθ"
|
||||
r := []rune(s)
|
||||
n, m := 2, 3
|
||||
kc := 'δ' // known character
|
||||
ks := "δε" // known string
|
||||
// for reference
|
||||
fmt.Println("Index: ", "01234567")
|
||||
fmt.Println("String:", s)
|
||||
// starting from n characters in and of m length
|
||||
fmt.Printf("Start %d, length %d: %s\n", n, m, string(r[n:n+m]))
|
||||
// starting from n characters in, up to the end of the string
|
||||
fmt.Printf("Start %d, to end: %s\n", n, string(r[n:]))
|
||||
// whole string minus last character
|
||||
fmt.Printf("All but last: %s\n", string(r[:len(r)-1]))
|
||||
// starting from a known character within the string and of m length
|
||||
dx := strings.IndexRune(s, kc)
|
||||
fmt.Printf("Start %q, length %d: %s\n", kc, m, string([]rune(s[dx:])[:m]))
|
||||
// starting from a known substring within the string and of m length
|
||||
sx := strings.Index(s, ks)
|
||||
fmt.Printf("Start %q, length %d: %s\n", ks, m, string([]rune(s[sx:])[:m]))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue