Reputation: 81
I have one string which looks like this :
"Způsob využití:\r\n\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\tobjekt k bydlení\r\n\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t"
I am confused that how i suppose to clean it? i want to remove everything which looks like :
\r
, \n
, \t
.
my output should be Způsob využití: objekt k bydlení
any help how i can achieve it? i am new to r and dont know much of it
Upvotes: 1
Views: 921
Reputation: 81
stringr::str_remove_all(x, "\\t|\\n|\\r")
is answer thanks to @user438383
Upvotes: 1
Reputation: 35554
You can use stringr::str_squish()
:
stringr::str_squish(x)
# [1] "Způsob využití: objekt k bydlení"
It can be achieved with base
:
trimws(gsub('\\s+', ' ', x))
Upvotes: 4
Reputation: 399
gsub("\\n|\\t|\\r", "", "Způsob využití:\r\n\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\tobjekt k bydlení\r\n\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t")
[1] "Způsob využití:objekt k bydlení"
Upvotes: 0