Logo

Programming-Idioms

History of Idiom 219 > diff from v32 to v33

Edit summary for version 33 by Puppy:
[Lua] " " creates a space as there's an empty char in there. "" is correct.

Version 32

2021-10-01, 14:21:59

Version 33

2021-11-23, 19:44:54

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