String Operations

Basic operations

Module

Functions

julia> number_to_string(121)
"121"
julia> number_to_string(121.12)
"121.12"

Grep Module

Module

UTCGP.str_grepModule

Grep Operations

Exports :

  • bundle_string_grep :
    • replace_pattern
    • replace\_first\_pattern
    • remove_pattern
source

Functions

julia> replace_pattern("HelloHello", "Hello", "hello")
"hellohello"

Also can remove a char :

julia> replace_pattern("Camel_case", "_", "")
"Camelcase"
julia> replace_first_pattern("HelloHello", "Hello", "hello")
"helloHello"
julia> replace_first_pattern("CCDC", "C", "A")
"ACDC"
julia> remove_pattern("HelloHello", "Hello")
""

Paste

Module

UTCGP.str_pasteModule

Paste Operations

Exports :

  • bundle_string_paste :
    • paste
    • paste_0
    • paste_with_space
  • bundle_string_concat_list_string :
    • paste_space_list_string
    • paste_list_string_sep
    • paste_list_string
source

Paste Strings

julia> paste("kebab", "case", "-")
"kebab-case"
julia> paste0("ju", "lia")
"julia"
julia> paste_with_space("ju", "lia")
"ju lia"

Paste List Strings

julia> paste_space_list_string(["kebab", "case"])
"kebab case"
julia> paste_list_string_sep(["kebab", "case"], "-")
"kebab-case"
julia> paste_list_string(["kebab", "case"])
"kebabcase"

Conditional

UTCGP.str_conditionalModule

Conditional Operations

Exports :

  • bundle_string_conditional :
    • if_string
    • if_not_string
    • if_else_string
    • longest_string
    • shortest_string
source

For if_string, if_not_string and if_else_string, the cond parameter is trunced to Int.

UTCGP.str_conditional.if_stringFunction
if_string(s::String, cond::Number, args...)::String

Returns the string s if the cond is different than 0. Else an empty string is returned.

cond is a Number, it is trunc to Int before comparison with 0.

source
julia> if_string("julia", 0)
""
julia> if_string("julia", 137287.2)
"julia"
UTCGP.str_conditional.if_not_stringFunction
if_not_string(s::String, cond::Number, args...)::String

This functions is the inverse of if_string.

Returns the string s if the cond is equal to 0. Else an empty string is returned. cond is a Number, it is trunc to Int before comparison with 0.

source
julia> if_not_string("julia", 0)
"julia"
julia> if_not_string("julia", 137287.2)
""
UTCGP.str_conditional.if_else_stringFunction
if_else_string(s1::String, s2::String, cond::Number, args...)::String

Returns the string s1 if the cond is different than 0. Else s2 is returned. cond is a Number, it is trunc to Int before comparison with 0.

source
julia> if_else_string("julia", "R" , 0)
"R"
julia> if_else_string("julia", "R" ,137287.2)
"julia"
julia> longest_string("julia", "R")
"julia"
julia> longest_string("julia", "jjjjj")
"julia"
julia> shortest_string("julia", "R")
"R"
julia> shortest_string("julia", "jjjjj")
"julia"

Lower, Upper, Capitalize

Module

UTCGP.str_capsModule

Lower Upper and Capitalize functions

Exports :

  • bundle_string_caps :
    • uppercase_
    • uppercase_at
    • uppercase_after
    • uppercase_char_after
    • uppercase_before
    • uppercase_char_before
    • lowercase_
    • lowercase_at
    • lowercase_after
    • lowercase_char_after
    • lowercase_before
    • lowercase_char_before
    • capitalize_first
    • capitalize_all
source

Upper Case

julia> uppercase_("julia")
"JULIA"
UTCGP.str_caps.uppercase_atFunction
uppercase_at(s::String, at::Number, args...)

Uppercases s at a given index at.

The index is clipped between 1 (the first index) and the length of s (the last index).

source
# It can capitalize
julia> uppercase_at("julia",1)
"Julia"
# index is clipped
julia> uppercase_at("julia",-100)
"Julia"
UTCGP.str_caps.uppercase_afterFunction
uppercase_after(s::String, after::String, args...)

Uppercases everything that comes after a match.

If after is empty, it returns the string s.

source
julia> uppercase_after("julia","ju")
"juLIA"
UTCGP.str_caps.uppercase_char_afterFunction
uppercase_char_after(s::String, after::String, args...)

Uppercases one character that comes after a match. It does that for every match.

If after is empty, it returns the string s.

source
julia> uppercase_char_after("julia","ju")
"juLia"
# it works on every match
julia> uppercase_char_after("julia julia","ju")
"juLia juLia"
UTCGP.str_caps.uppercase_beforeFunction
uppercase_before(s::String, before::String, args...)

Uppercases everything that comes before a match.

If before is empty, it returns the string s.

source
julia> uppercase_before("julia","lia")
"JUlia"
UTCGP.str_caps.uppercase_char_beforeFunction
uppercase_char_before(s::String, before::String, args...)

Uppercases one character that comes before a match. It does that for every match.

If before is empty, it returns the string s.

source
julia> uppercase_char_before("julia","lia")
"jUlia"
# it works on every match
julia> uppercase_char_before("julia julia","lia")
"jUlia jUlia"

Lower Case

julia> lowercase_("JULIA")
"julia"
UTCGP.str_caps.lowercase_atFunction
lowercase_at(s::String, at::Number, args...)

Lowercases s at a given index at.

The index is clipped between 1 (the first index) and the length of s (the last index).

source
julia> lowercase_at("JULIA",1)
"jULIA"
# index is clipped
julia> lowercase_at("JULIA",100)
"JULIa"
UTCGP.str_caps.lowercase_afterFunction
lowercase_after(s::String, after::String, args...)

Lowercases everything that comes after a match.

If after is empty, it returns the string s.

source
julia> lowercase_after("juLIA","ju")
"julia"
UTCGP.str_caps.lowercase_char_afterFunction
lowercase_char_after(s::String, after::String, args...)

Lowercases one character that comes after a match. It does that for every match.

If after is empty, it returns the string s.

source
julia> lowercase_char_after("JULIA","JU")
"JUlIA"
# it works on every match
julia> lowercase_char_after("JULIA JULIA","JU")
"JUlIA JUlIA"
UTCGP.str_caps.lowercase_beforeFunction
lowercase_before(s::String, before::String, args...)

Lowercases everything that comes before a match.

If before is empty, it returns the string s.

source
julia> lowercase_before("JULIA","LIA")
"juLIA"
UTCGP.str_caps.lowercase_char_beforeFunction
lowercase_char_before(s::String, before::String, args...)

Lowercases one character that comes before a match. It does that for every match.

If before is empty, it returns the string s.

source
julia> lowercase_char_before("JUlia","lia")
"Julia"
# it works on every match
julia> lowercase_char_before("JULIA JULIA","LIA")
"JuLIA JuLIA"

Capitalize

julia> capitalize_first("julia julia")
"Julia julia"
julia> capitalize_all("julia julia")
"Julia Julia"
# The titlecase functions takes all non letters as separators
julia> capitalize_all("julia-julia")
"Julia-Julia"