diff options
| author | Shulhan <m.shulhan@gmail.com> | 2019-09-27 00:47:54 +0700 |
|---|---|---|
| committer | Shulhan <m.shulhan@gmail.com> | 2019-09-27 00:49:49 +0700 |
| commit | 42f468352f6dd7202978517fbd0a94743b9e8a5b (patch) | |
| tree | 35c6dad4f8d8c68f37bbeaa10f7da88654449d97 /lib/bytes/bytes_example_test.go | |
| parent | 41294ceedd738cc44fe01dd0011ba7087a5d37fb (diff) | |
| download | pakakeh.go-42f468352f6dd7202978517fbd0a94743b9e8a5b.tar.xz | |
bytes: add function to get indexes of word in string
Unlike Indexes, the word parameter must be separated by space or placed
at beginning or end of string.
Diffstat (limited to 'lib/bytes/bytes_example_test.go')
| -rw-r--r-- | lib/bytes/bytes_example_test.go | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/bytes/bytes_example_test.go b/lib/bytes/bytes_example_test.go index 06b96146..dcb0e1ec 100644 --- a/lib/bytes/bytes_example_test.go +++ b/lib/bytes/bytes_example_test.go @@ -128,3 +128,13 @@ func ExampleTokenFind() { fmt.Printf("%d\n", at) // Output: 7 } + +func ExampleWordIndexes() { + s := []byte("moo moomoo moo") + token := []byte("moo") + + idxs := WordIndexes(s, token) + fmt.Println(idxs) + // Output: + // [0 11] +} |
