str
Collection of string related functions
Functions:
contains
contains(text: str, *args) -> bool
Check if text contains all given substrings.
Parameters:
Returns:
-
bool(bool) –True if all substrings are found in the text.
Source code in ipsl_common/str.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 | |
contains_any
contains_any(text: str, *args) -> bool
Check if text contains any of given substrings.
Parameters:
Returns:
-
bool(bool) –True if any of substrings is found in the text.
Source code in ipsl_common/str.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 | |
is_float
is_float(text: str) -> bool
Check if text represents floating value.
Parameters:
-
(textstr) –Text to verify
Returns:
-
bool(bool) –True if text represents a floating value.
Source code in ipsl_common/str.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
is_int
is_int(text: str) -> bool
Check if text represents integer value.
Parameters:
-
(textstr) –Text to verify
Returns:
-
bool(bool) –True if text represents an integer value.
Source code in ipsl_common/str.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
replace_text
replace_text(
text: str,
replacements: list[tuple[int, int, str]],
sort_replacements: bool = True,
) -> str
Replace given text by a collection of replacements. Each replacement defines starting and ending positions with a new text value to replace. If the start and end positions of a replacements are the same, the text will be inject at given position. Using an empty replacement text "" will remove text between start and end positions.
Parameters:
-
(textstr) –Text to replace
-
(replacementslist[tuple[int, int, str]]) –Collection of replacements of the form (start position, end position, new value).
-
(sort_replacementsbool, default:True) –Sort replacements by their start/end positions.
Returns: str: New text with applied replacements.
Source code in ipsl_common/str.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |