go: github.com/shurcooL/go/trim Index | Examples | Files

package trim

import "github.com/shurcooL/go/trim"

Package trim contains helpers for trimming strings.

Index

Examples

Package Files

trim.go

func FirstSpace Uses

func FirstSpace(s string) string

FirstSpace trims the first space character from s, if any.

Code:

fmt.Printf("%q\n", trim.FirstSpace(" String"))
fmt.Printf("%q\n", trim.FirstSpace("String"))
fmt.Printf("%q\n", trim.FirstSpace(" "))
fmt.Printf("%q\n", trim.FirstSpace(""))
fmt.Printf("%q\n", trim.FirstSpace("  String\n\n"))

Output:

"String"
"String"
""
""
" String\n\n"

func LastNewline Uses

func LastNewline(s string) string

LastNewline trims the last newline character from s, if any.

Code:

fmt.Printf("%q\n", trim.LastNewline("String\n"))
fmt.Printf("%q\n", trim.LastNewline("String"))
fmt.Printf("%q\n", trim.LastNewline("\n"))
fmt.Printf("%q\n", trim.LastNewline(""))
fmt.Printf("%q\n", trim.LastNewline("  String\n\n"))

Output:

"String"
"String"
""
""
"  String\n"

Package trim is imported by 9 packages. Updated 2016-07-21. Refresh now. Tools for package owners.