I have written a recursive to filter the string , but the output isn't my expected, could you please help assist this ?
s2 = "Hello"
def remove_text(s):
t = s.find(s2)
t2 = len(s2)
if t == -1:
return s
else:
if t == 0:
s = s[t2+1:]
else:
s = s[0:t-1] + s[t+len(s2):]
if s.find(s2) >= 0: #if still found s2 in s
remove_text(s)
s1 = "Hello my name is XXX Hello 12345 6 "
s3 = remove_text(s1)
print(s3)
the output i got always is "None" . I expected the output is:
my name is XXX 12345 6
return remove_text(s)in the last line of your function.s.text.replace("Hello", "")