Skip to content

Instantly share code, notes, and snippets.

@techykajal
Last active July 31, 2021 18:11
Show Gist options
  • Select an option

  • Save techykajal/3ed44f79238804aa0406b67934fdc87f to your computer and use it in GitHub Desktop.

Select an option

Save techykajal/3ed44f79238804aa0406b67934fdc87f to your computer and use it in GitHub Desktop.
def remove_newlines_tabs(text):
"""
This function will remove all the occurrences of newlines, tabs, and combinations like: \\n, \\.
arguments:
input_text: "text" of type "String".
return:
value: "text" after removal of newlines, tabs, \\n, \\ characters.
Example:
Input : This is her \\ first day at this place.\n Please,\t Be nice to her.\\n
Output : This is her first day at this place. Please, Be nice to her.
"""
# Replacing all the occurrences of \n,\\n,\t,\\ with a space.
Formatted_text = text.replace('\\n', ' ').replace('\n', ' ').replace('\t',' ').replace('\\', ' ').replace('. com', '.com')
return Formatted_text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment