MatrixMania/util/tools.py
2025-10-16 16:51:35 +02:00

22 lines
582 B
Python

def substring(string: str, start: int, end: int = 0) -> str:
"""
A substring function
:param string: The string
:param start: The starting index
:param end: The ending index. If None, this is set to the length of the substring :return:
"""
if not isinstance(string, str):
raise ValueError("No string provided")
if not isinstance(start, int):
raise ValueError("No starting index provided")
if end is None:
end = len(str)
result = ""
for i in range(start, end):
result += string[i]
return result