Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Python

Idiom #110 Check if string is blank

Set the boolean blank to true if the string s is empty, or null, or contains only whitespace ; false otherwise.

from re import sub
blank = not s or \
        not sub(r'\s+', '', s)
from string import whitespace as ws
blank = not s or \
        not any(x not in ws for x in s)
blank = not s or s.isspace()

not s evaluates to True for None and empty strings.
with Ada.Strings.Fixed;
use Ada.Strings.Fixed;
Blank := Index_Non_Blank (Str) = 0;

New implementation...