Logo

Programming-Idioms

History of Idiom 219 > diff from v33 to v34

Edit summary for version 34 by programming-idioms.org:
Restored version 32: No.

Version 33

2021-11-23, 19:44:54

Version 34

2021-11-23, 20:30:37

Idiom #219 Replace multiple spaces with single space

Create string t from the value of string s with each sequence of spaces replaced by a single space.

Explain if only the space characters will be replaced, or the other whitespaces as well: tabs, newlines.

Idiom #219 Replace multiple spaces with single space

Create string t from the value of string s with each sequence of spaces replaced by a single space.

Explain if only the space characters will be replaced, or the other whitespaces as well: tabs, newlines.

Extra Keywords
collapse repeated
Extra Keywords
collapse repeated
Code
local t = s:gsub("%s+", "")
Code
local t = s:gsub("%s+", " ")
Comments bubble
string.gsub(s, "%s+", " ") can be used instead of s:gsub("%s+", " ")
Comments bubble
string.gsub(s, "%s+", " ") can be used instead of s:gsub("%s+", " ")
Doc URL
https://www.lua.org/pil/20.2.html
Doc URL
https://www.lua.org/pil/20.2.html