Strings handler written in Bash.
source path/to/string/source.bash
awk -F : '{print $5}' /etc/passwd |
string_title
- string_lower
- string_upper
- string_title
- string_repeat
- string_scape
- string_replace
- string_replace_all
- string_dash_camelcase
- string_separator_camelcase
- string_underscore_camelcase
- string_camelcase_dash
- string_camelcase_separator
- string_camelcase_underscore
Lower case a string.
Passing string as argument:
string_lower "Some STRING" # some string
Using pipes:
echo "Some STRING" | string_lower # some string
Upper case a string.
Passing string as argument:
string_lower "Some string" # SOME STRING
Using pipes:
echo "Some string" | string_lower # SOME STRING
Capitalize a string.
Passing string as argument:
string_lower "some string" # Some String
Using pipes:
echo "some string" | string_lower # Some String
Repeat a string.
Passing string as argument:
string_repeat 2 "Some string\n"
# Some string
# Some string
Using pipes:
echo "*" | string_repeat 10 # **********
Escape an string.
Passing string as argument:
string_scape "That's my boy!" # That\'s my boy!
Using pipes:
echo 'We have some "rules"' | string_scape # We have some \"rules\"
Escaping a REGEX:
string_scape --type regex "He (Moody) loves to code." # He \(Moody\) loves to code\.
Replaces content of a string.
Passing string as argument:
string_replace "boy" "girl" "That's my boy." # That's my girl.
Using pipes
echo "John Doe" | string_replace "John" "Jane" # Jane Doe
Using REGEX:
string_replace -t regex "[^a-z]" "" "That's my boy." # hatsmyboy
Replaces all chars to a defined string
Passing string as argument:
string_replace_all "*" "p4ssw0rd" # ********
Using pipes
echo "p4ssw0rd" | string_replace_all "*" # ********
Convert dash to camelcase.
Passing string as argument:
string_dash_camelcase "This-is-a-string" # ThisIsAString
Using pipes:
echo "this-is-a-string" | string_dash_camelcase # thisIsAString
Convert separator to camelcase.
Passing string as argument:
string_separator_camelcase " " "This is a string" # ThisIsAString
Using pipes:
echo "this is a string" | string_separator_camelcase " " # thisIsAString
Convert underscore to camelcase.
Passing string as argument:
string_underscore_camelcase "This_is_a_string" # ThisIsAString
Using pipes:
echo "this_is_a_string" | string_underscore_camelcase # thisIsAString
Convert camelcase to dash.
Passing string as argument:
string_camelcase_dash "ThisIsAString" # This-Is-A-String
Using pipes:
echo "thisIsAString" | string_camelcase_dash # this-Is-A-String
Convert camelcase to separator.
Passing string as argument:
string_camelcase_separator " " "ThisIsAString" # This Is A String
Using pipes:
echo "thisIsAString" | string_camelcase_separator " " # this Is A String
Convert camelcase to underscore.
Passing string as argument:
string_camelcase_underscore "ThisIsAString" # This_Is_A_String
Using pipes:
echo "thisIsAString" | string_camelcase_underscore # this_Is_A_String