Cases examples! 🚀¶
✨ Extend your string powers with Str+
Setup [Optional]¶
Create a virtualenv 🔧
Create a new virtualenv before start this notebook to be able to select it as the kernel, if you want!
Create a new virtualenv.
pyenv virtualenv 3.9.16 .envStrPlus pyenv activate .envStrPlus pip install --upgrade pip pip install ipykernel
Delete the virtualenv.
pyenv deactivate .envStrPlus pyenv virtualenv-delete -f .envStrPlus
Should return empty
pyenv versions | grep .envStrPlus
Required! 💢¶
In [ ]:
Copied!
pip install --upgrade strplus
pip install --upgrade strplus
In [3]:
Copied!
from strplus import Str
from strplus import Str
😍 Simples use no parentheses!¶
In [4]:
Copied!
my_string = Str("Cast_this_string_TO_Pascal!")
my_string.pascal
my_string = Str("Cast_this_string_TO_Pascal!")
my_string.pascal
Out[4]:
'CastThisStringToPascal'
In [5]:
Copied!
my_string = Str("cast_this_string_to_camel")
my_string.camel
my_string = Str("cast_this_string_to_camel")
my_string.camel
Out[5]:
'castThisStringToCamel'
In [6]:
Copied!
my_string = Str("Cast_this_StringToSnake")
my_string.snake
my_string = Str("Cast_this_StringToSnake")
my_string.snake
Out[6]:
'cast_this_string_to_snake'
🔥 You can use with parentheses also!¶
Snake examples 🐍¶
In [7]:
Copied!
Str("CastMeUseLikeANormalFunction").to_snake()
Str("CastMeUseLikeANormalFunction").to_snake()
Out[7]:
'cast_me_use_like_a_normal_function'
In [8]:
Copied!
Str("CastThisPath/2021/01/01").to_snake()
Str("CastThisPath/2021/01/01").to_snake()
Out[8]:
'cast_this_path_2021_01_01'
Pascal examples 🐫¶
In [9]:
Copied!
Str("cast_this_path_to_pascal/2021/01/01").to_pascal()
Str("cast_this_path_to_pascal/2021/01/01").to_pascal()
Out[9]:
'CastThisPathToPascal20210101'
In [10]:
Copied!
Str("cat me to_Pascal Please").to_pascal()
Str("cat me to_Pascal Please").to_pascal()
Out[10]:
'CatMeToPascalPlease'
Camel 🐪¶
In [11]:
Copied!
my_string.to_camel()
my_string.to_camel()
Out[11]:
'castThisStringToSnake'
In [12]:
Copied!
Str("reference dataset").to_camel()
Str("reference dataset").to_camel()
Out[12]:
'referenceDataset'
Complex 👽¶
In [13]:
Copied!
# Complex return, recursive Str
Str("MyStringWorks").to_snake().split("_")[0].pascal
# Complex return, recursive Str
Str("MyStringWorks").to_snake().split("_")[0].pascal
Out[13]:
'My'
Common behavior 👌
"_".join returns a str class not a not or Str with the good features! In the Str we only have recessivity we are not overwriting the str from the global to Str, so it's normal and expected that behavior
In [14]:
Copied!
try:
"_".join(Str("MyStringWorks").to_snake().split("_")[0:1]).pascal
except Exception as e:
print(e)
try:
"_".join(Str("MyStringWorks").to_snake().split("_")[0:1]).pascal
except Exception as e:
print(e)
'str' object has no attribute 'pascal'
In [15]:
Copied!
# you always has the built-in native Python functions
my_string.upper()
# you always has the built-in native Python functions
my_string.upper()
Out[15]:
'CAST_THIS_STRINGTOSNAKE'
😏 Just use a specif function if you prefer!¶
In [16]:
Copied!
from strplus.functions import *
from strplus.functions import *
In [17]:
Copied!
to_camel("parse_to_camel")
to_camel("parse_to_camel")
Out[17]:
'parseToCamel'
In [18]:
Copied!
to_snake("ThisIsAnotherTest")
to_snake("ThisIsAnotherTest")
Out[18]:
'this_is_another_test'
In [19]:
Copied!
### Run project local 📀
# import os
# import sys
# sys.path.insert(0, os.path.abspath("../.."))
# sys.path.insert(0, os.path.abspath(".."))
### Run project local 📀
# import os
# import sys
# sys.path.insert(0, os.path.abspath("../.."))
# sys.path.insert(0, os.path.abspath(".."))