Hello R users,

I have a string, for example:
x <- "\t\tabc\t def"

This string can contain any number of tabulations. I want to replace each
tabulation of the begining of the string by the same number of space:
"  abc\t def"

I'm trying to do this with gsub :
> gsub("\t", " ", x) # replace every \t
[1] "  abc  def"
> sub("^\t", " ", x) # replace only the first \t
[1] " \tabc\t def"
> sub("^\t*", " ", x) # replace all beginning \t, but only one space
[1] " abc\t def"

How can I do this ?

Thank you very much.

david

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to