Check String for Spaces

Published by Helen Yu in

Create a function that returns true if a string contains any spaces.

Examples

has_spaces("hello") ➞ false

has_spaces("hello, world") ➞ true

has_spaces(" ") ➞ true

has_spaces("") ➞ false

has_spaces(",./!@#") ➞ false

Notes

  • An empty string does not contain any spaces.
  • Try doing this without RegEx.
Watch a quick demo on how Edabit works.