Skip to content

String Tools

Functions for manipulating strings.


is_prefixed

is_prefixed(value, prefix)

Check whether a string starts with the given prefix.

Parameters:

Name Type Description Default
value str

The string to check.

required
prefix str

The prefix to look for.

required

Returns:

Type Description
bool

True if value starts with prefix.

Source code in src/aibs_informatics_core/utils/tools/strtools.py
17
18
19
20
21
22
23
24
25
26
27
def is_prefixed(value: str, prefix: str) -> bool:
    """Check whether a string starts with the given prefix.

    Args:
        value: The string to check.
        prefix: The prefix to look for.

    Returns:
        True if ``value`` starts with ``prefix``.
    """
    return value.startswith(prefix)

is_suffixed

is_suffixed(value, suffix)

Check whether a string ends with the given suffix.

Parameters:

Name Type Description Default
value str

The string to check.

required
suffix str

The suffix to look for.

required

Returns:

Type Description
bool

True if value ends with suffix.

Source code in src/aibs_informatics_core/utils/tools/strtools.py
30
31
32
33
34
35
36
37
38
39
40
def is_suffixed(value: str, suffix: str) -> bool:
    """Check whether a string ends with the given suffix.

    Args:
        value: The string to check.
        suffix: The suffix to look for.

    Returns:
        True if ``value`` ends with ``suffix``.
    """
    return value.endswith(suffix)

lowercase

lowercase(value)

Convert a string to lowercase.

Parameters:

Name Type Description Default
value str

The string to convert.

required

Returns:

Type Description
str

The lowercased string.

Source code in src/aibs_informatics_core/utils/tools/strtools.py
75
76
77
78
79
80
81
82
83
84
def lowercase(value: str) -> str:
    """Convert a string to lowercase.

    Args:
        value: The string to convert.

    Returns:
        The lowercased string.
    """
    return value.lower()

removeprefix

removeprefix(value, prefix)

Remove the given prefix from the beginning of a string.

Parameters:

Name Type Description Default
value str

The original string.

required
prefix str

The prefix to remove.

required

Returns:

Type Description
str

The string with the prefix removed, or the original string if not prefixed.

Source code in src/aibs_informatics_core/utils/tools/strtools.py
43
44
45
46
47
48
49
50
51
52
53
def removeprefix(value: str, prefix: str) -> str:
    """Remove the given prefix from the beginning of a string.

    Args:
        value: The original string.
        prefix: The prefix to remove.

    Returns:
        The string with the prefix removed, or the original string if not prefixed.
    """
    return value.removeprefix(prefix)

removesuffix

removesuffix(value, suffix)

Remove the given suffix from the end of a string.

Parameters:

Name Type Description Default
value str

The original string.

required
suffix str

The suffix to remove.

required

Returns:

Type Description
str

The string with the suffix removed, or the original string if not suffixed.

Source code in src/aibs_informatics_core/utils/tools/strtools.py
56
57
58
59
60
61
62
63
64
65
66
def removesuffix(value: str, suffix: str) -> str:
    """Remove the given suffix from the end of a string.

    Args:
        value: The original string.
        suffix: The suffix to remove.

    Returns:
        The string with the suffix removed, or the original string if not suffixed.
    """
    return value.removesuffix(suffix)

uppercase

uppercase(value)

Convert a string to uppercase.

Parameters:

Name Type Description Default
value str

The string to convert.

required

Returns:

Type Description
str

The uppercased string.

Source code in src/aibs_informatics_core/utils/tools/strtools.py
87
88
89
90
91
92
93
94
95
96
def uppercase(value: str) -> str:
    """Convert a string to uppercase.

    Args:
        value: The string to convert.

    Returns:
        The uppercased string.
    """
    return value.upper()