diff options
| author | Shulhan <ms@kilabit.info> | 2023-03-22 13:54:25 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2023-03-22 13:54:25 +0700 |
| commit | 3bd5fad4c0a972dd279ecfbf77de31838764f609 (patch) | |
| tree | df472c89f6b423c72f0dd421b49858b317220a73 /lib/bytes/bytes_example_test.go | |
| parent | e2cb490e54e7e71109b3a681fd26519a06f29c2c (diff) | |
| download | pakakeh.go-3bd5fad4c0a972dd279ecfbf77de31838764f609.tar.xz | |
lib/bytes: add function SplitEach
The SplitEach funciton split the slice of byte into n number of bytes.
If n is less or equal than zero, it will return the data as chunks.
Diffstat (limited to 'lib/bytes/bytes_example_test.go')
| -rw-r--r-- | lib/bytes/bytes_example_test.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/bytes/bytes_example_test.go b/lib/bytes/bytes_example_test.go index 314275d2..da8dcce2 100644 --- a/lib/bytes/bytes_example_test.go +++ b/lib/bytes/bytes_example_test.go @@ -351,6 +351,22 @@ func ExampleSnippetByIndexes() { // reserved. } +func ExampleSplitEach() { + var data = []byte(`Hello`) + + fmt.Printf("%s\n", SplitEach(data, 0)) + fmt.Printf("%s\n", SplitEach(data, 1)) + fmt.Printf("%s\n", SplitEach(data, 2)) + fmt.Printf("%s\n", SplitEach(data, 5)) + fmt.Printf("%s\n", SplitEach(data, 10)) + // Output: + // [Hello] + // [H e l l o] + // [He ll o] + // [Hello] + // [Hello] +} + func ExampleTokenFind() { text := []byte("// Copyright 2018, Shulhan <ms@kilabit.info>. All rights reserved.") |
