-
-
Notifications
You must be signed in to change notification settings - Fork 0
string
This class includes methods for working with strings.
This method will try to convert a string to a fitting Python type or structure (a string "{'key': ['val1', 'val2']}" becomes a dictionary {"key": ["val1", "val2"]}).
Param: string: str the string to be converted to its type
Returns: the string as a type
This method will replace all special space characters with normal spaces.
Params:
-
string: strthe string to normalize -
tab_spaces: int = 4the amount of spaces to replace tab characters with (default4)
Returns: the string with all spaces normalized
This method will escape all of Python's special characters (e.g. \n, \t, ...) and quotes inside a string.
Params:
-
string: strthe string to escape -
str_quotes: str = '"'the quotes, the string will later be inside of
Returns: The string with special characters and quotes escaped
If the string is later placed in double-quotes like "some string" then str_quotes should be ".
The same thing goes for a string like 'another string', in which case str_quotes should be '.
The quotes will be escaped the following way:
- If
str_quotesis"and the given string issome "string" inside a string, the quotes will be escaped, so the output issome \"string\" inside a string. - If
str_quotesis', though, and the given string issome "string" inside a string, the quotes will not be escaped because their not the same type of quotes.
This method will simply check if the input is None or an empty string (or a string consisting only of spaces).
Params:
-
string: strthe string to check if it's empty -
spaces_are_empty: bool = Falsewhether to check if the string is only spaces
Returns: True if the string is empty, False otherwise
This method checks if the given string consists of only the same character and if yes, returns the number of times that character is present.
Params:
-
string: strthe string to check -
char: strthe character to check for
Returns:
if the string consists of only the same char, it returns the number of times the character is present
if the string doesn't consist of only the same character, it returns False
This method will decompose a cased string into its individual parts.
Params:
-
case_string: strthe string to decompose -
seps: str = "-_"the characters that separate the parts -
lower_all: bool = Truewhether to lowercase all the parts
Returns: a list with the decomposed string parts
This method will convert a string of any type of casing to UpperCamelCase or lowerCamelCase.
Params:
-
string: strthe string to convert -
upper: bool = Truewhether to convert to UpperCamelCase
Returns: the string with the new casing
This method will convert a string of any type of casing to a delimited string.
Params:
-
string: strthe string to convert -
delimiter: str = "_"the delimiter to use -
screaming: bool = Falsewhether to use screaming case (all parts in uppercase)
Returns: the string with the new delimited casing
This method will split the given string by newlines and optionally remove empty lines.
Params:
-
string: strthe string to split -
remove_empty_lines: bool = Falsewhether to remove empty lines
Returns: a list with the split lines
This method will remove consecutive empty lines from the given string, up to max_consecutive empty lines.
Params:
-
string: strthe string to remove consecutive empty lines from -
max_consecutive: int = 0the maximum amount of consecutive empty lines to keep
Returns: the string with consecutive empty lines removed
This method will split the given string every count characters.
Params:
-
string: strthe string to split -
count: intthe number of characters by which the string is split
Returns: a list with the split string parts
★⠀Python Library by XulbuX⠀★
-
Intended Audience:
- Developers
-
License:
- OSI Approved
- MIT License
-
Operating Systems:
- Full Library: OS Independent
-
Supported Python Versions:
- Python 3.13
- Python 3.12
- Python 3.11
- Python 3.10
-
Topics:
- Libraries
- Python Modules
- Software Development