From 42f468352f6dd7202978517fbd0a94743b9e8a5b Mon Sep 17 00:00:00 2001 From: Shulhan Date: Fri, 27 Sep 2019 00:47:54 +0700 Subject: 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. --- lib/bytes/bytes_example_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib/bytes/bytes_example_test.go') 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] +} -- cgit v1.3-6-g1900