Logo

Programming-Idioms

  • Kotlin
  • Perl
  • C#

Idiom #320 Test if string is empty

Set b to true if the string s is empty, false otherwise

var b = string.IsNullOrEmpty(s);
use strict;
my $b = $s eq '';

If $s is undefined, then it will be treated as equal to an empty string. But, an uninitialized value warning will be issued.
#include <string.h>
bool b = !strlen(s);

C23 bool

New implementation...
< >
programming-idioms.org