From eb64ecf0907c2a2deae0687592eb3910e9c328cc Mon Sep 17 00:00:00 2001 From: JadSark Date: Thu, 14 Dec 2023 16:19:13 +0100 Subject: [PATCH] Bug027 fixed --- source/BUG/strings.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/source/BUG/strings.py b/source/BUG/strings.py index 426b84e..0410fa5 100644 --- a/source/BUG/strings.py +++ b/source/BUG/strings.py @@ -50,7 +50,11 @@ def replace_substring(s: str, old_sub: str, new_sub: str) -> str: """ BUG027: replace_substring should replace occurrences of old_sub with new_sub, not append new_sub. """ - result = s + new_sub + result = s + index=result.find(old_sub) + while index != -1: + result= result[:index] + new_sub + result[index+len(old_sub):] + index=result.find(old_sub) return result