Code
def replace_inside_parentheses(string, find_string, replace_string):
bracket_count = 0
return_string = ""
for a in string:
if a == "(":
bracket_count += 1
elif a == ")":
bracket_count -= 1
if bracket_count > 0:
return_string += a.replace(find_string, replace_string)
else:
return_string += a
return return_string
my_str = "decimal(12,01)"
print(my_str)
print(replace_inside_parentheses(my_str, ",", "%"))
No comments:
Post a Comment