Eliminating spaces in a string

Hi, community.
I have a vector like
String <- ("math course", english course ")

I need Remove empty spaces in each element of the vector.
What function do I use?

Here are two solutions for removing all spaces.

String <- c("math course", "english course ")
gsub(" ", "", String)
#> [1] "mathcourse"    "englishcourse"

library(stringr)
str_remove_all(String, " ")
#> [1] "mathcourse"    "englishcourse"

Created on 2019-08-31 by the reprex package (v0.2.1)

2 Likes

thank you, FJCC.

Thank you for your help.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.