Logo

Programming-Idioms

History of Idiom 219 > diff from v34 to v35

Edit summary for version 35 by programming-idioms.org:
[Lua] +DemoURL

Version 34

2021-11-23, 20:30:37

Version 35

2021-11-23, 20:31:07

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
Demo URL
http://codepad.org/O9Sp0F8I