Update all new Tasks
This commit is contained in:
parent
00a190b0a6
commit
91df62d461
5697 changed files with 93386 additions and 804 deletions
30
Task/String-matching/Go/string-matching.go
Normal file
30
Task/String-matching/Go/string-matching.go
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func match(first, second string) {
|
||||
fmt.Printf("1. %s starts with %s: %t\n",
|
||||
first, second, strings.HasPrefix(first, second))
|
||||
i := strings.Index(first, second)
|
||||
fmt.Printf("2. %s contains %s: %t,\n", first, second, i >= 0)
|
||||
if i >= 0 {
|
||||
fmt.Printf("2.1. at location %d,\n", i)
|
||||
for start := i+1;; {
|
||||
if i = strings.Index(first[start:], second); i < 0 {
|
||||
break
|
||||
}
|
||||
fmt.Printf("2.2. at location %d,\n", start+i)
|
||||
start += i+1
|
||||
}
|
||||
fmt.Println("2.2. and that's all")
|
||||
}
|
||||
fmt.Printf("3. %s ends with %s: %t\n",
|
||||
first, second, strings.HasSuffix(first, second))
|
||||
}
|
||||
|
||||
func main() {
|
||||
match("abracadabra", "abr")
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue