Documentation
¶
Overview ¶
Package stringutil provides common sense string manipulation methods from ruby.
How to use:
package main import "github.com/wallclockbuilder/stringutil" func main() { stringutil.Capitalize("abcde") #=> "ABCDE" stringutil.Reverse("stressed") #=> "desserts" stringutil.Swapcase("Hello") #=> "hELLO" }
Index ¶
- func Capitalize(s string) string
- func Chomp(s string, sep string) string
- func Chop(s string) string
- func Chr(s string) string
- func Downcase(s string) string
- func Empty(s string) bool
- func Include(s string, substr string) bool
- func Length(s string) int
- func Lstrip(s string) string
- func Prepend(s string, item string) string
- func Reverse(s string) string
- func Rstrip(s string) string
- func Size(s string) int
- func Start_with(s string, prefix string) bool
- func Strip(s string) string
- func Swapcase(s string) string
- func Upcase(s string) string
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Capitalize ¶
Capitalize returns a new string with the first character converted to uppercase and the remainder to lowercase. Note: case conversion is effective only in ASCII region.
Example ¶
fmt.Println(Capitalize("bare necessities"))
Output: BARE NECESSITIES
func Chomp ¶
Chomp Returns a new String with the given record separator(sep) removed from the end of string(s) if present. Chomp also removes carriage return characters (that is it will remove \n, \r, and \r\n). If sep is an empty string, it will remove all trailing newlines from the string.
Example ¶
fmt.Println(Chomp("hello", "llo")) fmt.Println(Chomp("hello\n", "")) fmt.Println(Chomp("hello\r\n", ""))
Output: he hello hello
func Chop ¶
Chop returns a new String with the last character removed. If the string ends with \r\n, both characters are removed. Applying chop to an empty string returns an empty string.
Example ¶
fmt.Println(Chop("Keep it simple")) fmt.Println(Chop("Keep it simple\n")) fmt.Println(Chop("Developer happiness FTW\r\n"))
Output: Keep it simpl Keep it simple Developer happiness FTW
func Chr ¶
Chr Returns the one-character string at the beginning of the string s.
Example ¶
fmt.Println(Chr("abcde"))
Output: a
func Downcase ¶
Downcase returns a copy of str with all uppercase letters replaced with their lowercase counterparts.
Example ¶
fmt.Println(Downcase("hEllO"))
Output: hello
func Empty ¶
Empty returns true if s has a length of zero.
Example ¶
fmt.Println(Empty("hello")) fmt.Println(Empty(" ")) fmt.Println(Empty(""))
Output: false false true
func Include ¶
Include returns true if str contains the given string or character.
Example ¶
fmt.Println(Include("hello", "lo")) fmt.Println(Include("hello", "ol")) fmt.Println(Include("hello", "?h"))
Output: true false true
func Length ¶
Length returns the character length of s.
Example ¶
fmt.Println(Length("hello"))
Output: 5
func Lstrip ¶
Lstrip returns a copy of s with leading whitespace removed. See also stringutil.Rstrip and stringutil.Strip
func Prepend ¶
Prepend returns a new string with item at the head of s.
Example ¶
fmt.Println(Prepend("planet", "capt. "))
Output: capt. planet
func Reverse ¶
Reverse returns a new string with the characters from s in reverse order.
Example ¶
fmt.Println(Reverse("yo")) fmt.Println(Reverse("dog")) fmt.Println(Reverse("stressed"))
Output: oy god desserts
func Rstrip ¶
Rstrip returns a copy of s with trailing whitespace removed. See also stringutil.Lstrip and stringutil.Strip
Example ¶
fmt.Println(Rstrip(" hello "))
Output: hello
func Start_with ¶
Start_with returns true if s starts the prefix given.
Example ¶
fmt.Println(Start_with("hello", "hell"))
Output: true
func Strip ¶
Strip returns a copy of str with leading and trailing whitespace removed.
Example ¶
fmt.Println(Strip(" hello ")) fmt.Println(Strip("\tgoodbye\r\n"))
Output: hello goodbye
func Swapcase ¶
Swapcase returns a copy of str with uppercase alphabetic characters converted to lowercase and lowercase characters converted to uppercase. Note: case conversion is effective only in ASCII region.
Example ¶
fmt.Println(Swapcase("Hello")) fmt.Println(Swapcase("cYbEr_PuNk11")) fmt.Println(Swapcase("abcdefghijklmnopqrstuvwxyz")) fmt.Println(Swapcase("developer HAPPINESS"))
Output: hELLO CyBeR_pUnK11 ABCDEFGHIJKLMNOPQRSTUVWXYZ DEVELOPER happiness
Types ¶
This section is empty.