I have this sentence that contains "& / ?".
c = "Do Sam&Lilly like yes/no questions?"
I want to add a whitespace before and after each of the special characters to get
"Do Sam & Lilly like yes / no questions ? "
I can only get this by the hard way:
c = gsub("[&]", " & ", c)
c = gsub("[/]", " / ", c)
c = gsub("[?]", " ? ", c)
But imagine that I have many of these special character, which warrants using [:alnum:]. So I am really looking for a solution that looks like this:
gsub("[[:alnum:]]", " [[:alnum:]] ", c)
Unfortunately, I cannot use [:alnum:] as the second argument this way.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…