How can I remove tabs from a string in Ruby?

I have a program that loads tab-delimited rows into a MySQL table. One of the values ​​has tabs in it, which causes some problems. The data is created column by column, so I need to find a way to strip the tab character from a separate field using gsub. However, I do not want to get rid of anything else, such as spaces.

+3
source share
2 answers

Very simple \t- a tab character.

result = string.gsub /\t/, ''

or, on the spot

string.gsub! /\t/, ''
+15
source

\t- escape character for tabs inside lines. That way, you can just search "\t"and replace it with a space or something.

+1
source

All Articles