Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View 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])
}

View 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]))
}

View file

@ -1,14 +0,0 @@
package main
import "fmt"
import "strings"
func main() {
s := "ABCDEFGH"
n, m := 2, 3
fmt.Println(s[n:n+m]) // "CDE"
fmt.Println(s[n:]) // "CDEFGH"
fmt.Println(s[0:len(s)-1]) // "ABCDEFG"
fmt.Println(s[strings.Index(s, "D"):strings.Index(s, "D")+m]) // "DEF"
fmt.Println(s[strings.Index(s, "DE"):strings.Index(s, "DE")+m]) // "DEF"
}