Search⌘ K

Remove Tabs in a String

Understand how to remove all tabs and space characters from a string using recursion. This lesson teaches the base case and recursive steps needed to manipulate strings, helping you build confidence in recursive string processing techniques.

What does “Removing Tabs from a String” mean?

Our task is to remove all tabs from a string. This includes the character \t and " " from a string.

Removing spaces from a string
Removing spaces from a string

Implementation

Python 3.5
def remove(string):
# Base Case
if not string:
return ""
# Recursive Case
if string[0] == "\t" or string[0] == " ":
return remove(string[1:])
else:
return string[0] + remove(string[1:])
# Driver Code
print(remove("Hello\tWorld"))
...