Skip to content

Commit 985c3ce

Browse files
authored
Merge pull request #770 from devlights/add-strings-trimspace-example
2 parents 782c23c + 606be28 commit 985c3ce

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

examples/basic/strs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@
1212
| rune_count.go | string_rune_count | utf8.RuneCountInString() のサンプルです. |
1313
| diff_trimright_trimsuffix.go | string_diff_trimright_trimsuffix | strings.TrimRight と strings.TrimSuffix のちょっとした違いについてのサンプルです. |
1414
| using_string_clone.go | string_using_clone | Go 1.18 で追加された strings.Clone() のサンプルです |
15+
| trimspace.go | string_trim_space | strings.TrimSpace() のサンプルです. |

examples/basic/strs/examples.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ func (r *register) Regist(m mapping.ExampleMapping) {
2222
m["string_diff_trimright_trimsuffix"] = DiffTrimRightAndTrimSuffix
2323
m["string_cut_prefix_suffix"] = CutPrefixSuffix
2424
m["string_using_clone"] = UsingStringsClone
25+
m["string_trim_space"] = TrimSpace
2526
}

examples/basic/strs/trimspace.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package strs
2+
3+
import (
4+
"strings"
5+
6+
"github.com/devlights/gomy/output"
7+
)
8+
9+
// TrimSpace は、strings.TrimSpace() のサンプルです.
10+
//
11+
// 両端のスペースをトリミングしてくれる。
12+
//
13+
// > TrimSpace returns a slice of the string s, with all leading and trailing white space removed, as defined by Unicode.
14+
//
15+
// > (TrimSpaceは、Unicodeで定義されているように、すべての先頭と末尾の空白を除去した文字列sのスライスを返します。)
16+
//
17+
// # REFERENCES
18+
// - https://pkg.go.dev/strings@go1.22.1#TrimSpace
19+
func TrimSpace() error {
20+
var (
21+
withSpace = " hello world "
22+
noSpace = "hello world"
23+
)
24+
25+
output.Stdoutf("[withSpace]", "%q\n", strings.TrimSpace(withSpace))
26+
output.Stdoutf("[noSpace ]", "%q\n", strings.TrimSpace(noSpace))
27+
28+
return nil
29+
}

0 commit comments

Comments
 (0)