Logo

Programming-Idioms

History of Idiom 219 > diff from v23 to v24

Edit summary for version 24 by topit:
New Lua implementation by user [topit]

Version 23

2021-03-19, 14:10:07

Version 24

2021-04-12, 17:27:48

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+", " ")
Comments bubble
string.gsub(s, "%s+", " ") can be used instead of s:gsub("%s+", " ")
Doc URL
https://www.lua.org/pil/20.2.html