How can I remove space before and after @?
For example,
safety@ gmail.com / ghjv@gmail.com
gjhv_mf6 @ hotmail.com,hhty @gmail.com
the desired output will be:
safety@gmail.com / ghjv@gmail.com
gjhv_mf6@hotmail.com,hhty@gmail.com
How can I remove space before and after @?
For example,
safety@ gmail.com / ghjv@gmail.com
gjhv_mf6 @ hotmail.com,hhty @gmail.com
the desired output will be:
safety@gmail.com / ghjv@gmail.com
gjhv_mf6@hotmail.com,hhty@gmail.com
gsub()
should do it.
string_vec <- c("safety@ gmail.com / ghjv@gmail.com",
"gjhv_mf6 @ hotmail.com,hhty @gmail.com")
gsub(" *@ *","@",string_vec)
If you want to remove all whitespace (including tabs etc.), follow this question:
gsub("[[:space:]]*@[[:space:]]*", "@", string_vec)
Another option it to remove optional whitespace before and after "@"
.
Using @BenBolker's data
gsub("\\s?@\\s?", "@", string_vec)
#[1] "safety@gmail.com / ghjv@gmail.com" "gjhv_mf6@hotmail.com,hhty@gmail.com"
OR with stringr::str_replace_all
stringr::str_replace_all(string_vec, "\\s?@\\s?", "@")