diff options
| author | Shulhan <ms@kilabit.info> | 2021-09-25 00:11:50 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2021-09-25 00:39:03 +0700 |
| commit | 66623443235edcdd838546be9b939bd8274d92e4 (patch) | |
| tree | f58b8ae292fe00a17b00b49dbb00067bc1018652 /lib/strings/string_example_test.go | |
| parent | c0c9a5c6a0d32a61f359cb68fe409d471ec60d90 (diff) | |
| download | pakakeh.go-66623443235edcdd838546be9b939bd8274d92e4.tar.xz | |
lib/strings: add function Alnum
The Alnum remove non alpha-numeric character from text and return it.
Its accept the string to be cleanup and boolean parameter withSpace.
If withSpace is true then white space is allowed, otherwise it would
also be removed from text.
Diffstat (limited to 'lib/strings/string_example_test.go')
| -rw-r--r-- | lib/strings/string_example_test.go | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/strings/string_example_test.go b/lib/strings/string_example_test.go index 5b8f6847..7d26fc12 100644 --- a/lib/strings/string_example_test.go +++ b/lib/strings/string_example_test.go @@ -8,6 +8,27 @@ import ( "fmt" ) +func ExampleAlnum() { + cases := []struct { + text string + withSpace bool + }{ + {"A, b.c", false}, + {"A, b.c", true}, + {"A1 b", false}, + {"A1 b", true}, + } + + for _, c := range cases { + fmt.Printf("%s\n", Alnum(c.text, c.withSpace)) + } + //Output: + //Abc + //A bc + //A1b + //A1 b +} + func ExampleCleanURI() { text := `You can visit ftp://hostname or https://hostname/link%202 for more information` |
