Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to replace tabs in a string?

Tags:

python

I need to replace tabs in a string, but only the tabs, not the spaces.

If I use the str.replace() function, what would go in the first set of quotes?

like image 200
PierreTroodoo Avatar asked Mar 19 '15 05:03

PierreTroodoo


People also ask

How do I replace a tab in a text?

Press Ctrl-H to open the Replace dialogue, paste (Ctrl-V) into the Find what box and enter what you want to replace with in the Replace with box. This will be either nothing or perhaps a single space, depending on where the unwanted tabs are.

How do I replace a tab in a string in Java?

You can simply use this regular expression to replace any type of escapes( including tabs, newlines, spaces etc.) within a String with the desired one: lineOfText. replaceAll("\\s", " ");

How do I find and replace tabs?

To find and replace text in Word, click the “Replace” button in the “Editing” button group on the “Home” tab of the Ribbon. The “Find and Replace” dialog box opens and shows the “Replace” tab.

How do you replace part of a string?

Python String | replace() replace() is an inbuilt function in the Python programming language that returns a copy of the string where all occurrences of a substring are replaced with another substring. Parameters : old – old substring you want to replace. new – new substring which would replace the old substring.


1 Answers

In python string literals, the '\t' pair represents the tab character. So you would use mystring.replace('\t', 'any other string that you want to replace the tab with').

like image 186
Tritium21 Avatar answered Oct 15 '22 05:10

Tritium21