Media-Manager/Universal/tools.py

14 lines
608 B
Python
Raw Permalink Normal View History

def replace(input_str, search_key, replace_str, checkspaces=False):
if replace_str is None:
input_str = replace(input_str, search_key, "", checkspaces)
else:
while input_str.find(search_key) != -1:
if checkspaces:
if input_str[input_str.index(search_key) - 1] != " ":
input_str = input_str.replace(search_key, " " + replace_str)
else:
input_str = input_str.replace(search_key, replace_str)
else:
input_str = input_str.replace(search_key, replace_str)
return input_str