简体   繁体   中英

Replace all double spaces with single spaces in string

I would like to reduce all spaces longer than a single space in a string to a single space.

foo(" 1   2    3     4                 5 ")
[1] " 1 2 3 4 5 "

That would work:

gsub(' +',' ',foo) 

:)

(edited to take into account Zach's comment)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM