Logo

Programming-Idioms

  • Python
  • Ruby
  • JS
  • Java

Idiom #320 Test if string is empty

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

b = s == ''
b = not s
b = s.empty?
let b = !!s
boolean b = s.equals("");
boolean b = s.intern() == "";

If you're comparing a String reference to a String literal, you can use the equality operator if you "intern" the reference.
#include <string.h>
bool b = !strlen(s);

C23 bool

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