Logo

Programming-Idioms

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

Implementation edit is for fixing errors and enhancing with metadata. Please do not replace the code below with a different implementation.

Instead of changing the code of the snippet, consider creating another Perl implementation.

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
import org.apache.commons.lang3.StringUtils;
boolean blank = StringUtils.isBlank(s);
import "strings"
blank := strings.TrimSpace(s) == ""
import std.algorithm;
import std.uni;
bool blank = s.all!isSpace;
blank := trim(s) = '';
import Data.Char (isSpace)
b = null (dropWhile isSpace s)
with Ada.Strings.Fixed;
use Ada.Strings.Fixed;
Blank := Index_Non_Blank (Str) = 0;
blank = not s or s.isspace()
import Data.Char (isSpace)
blank :: Bool
blank = all isSpace s
$blank = (empty(trim($s));
$blank = !trim($s);
blank = s.nil? or s.strip.empty?
let blank = s.trim().is_empty();
blank = s == nil || String.length(String.trim s) == 0
const blank = s == null || s.trim() === ''
val blank = Option(s).forall(_.trim.isEmpty)
boolean blank = s==null || s.strip().isEmpty();
bool blank = string.IsNullOrWhiteSpace(s);
bool blank = string.IsNullOrWhiteSpace(s);
(setf blank (not (find #\space s :test-not #'eql)))
#include <algorithm>
#include <cctype>
#include <string>
bool blank = false;
if (s.empty() || std::all_of(s.begin(), s.end(), [](char c){return std::isspace(c);})) {
      blank = true;
}
blank = s == ''
Blank = string:is_empty(string:trim(S)).
(require '[clojure.string :refer [blank?]])
(blank? s)
IDENTIFICATION DIVISION.
PROGRAM-ID. blank string.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 BOOLEAN-BLANK     PIC X.
   88 BLANK          VALUE "T".
   88 NOT-BLANK      VALUE "F".
PROCEDURE DIVISION.
    IF s > SPACES
       SET BLANK     TO TRUE
    ELSE
       SET NOT-BLANK TO TRUE
    END-IF 	 	
STOP RUN.
Dim blank As Boolean = String.IsNullOrWhitespace(s)
val blank = s.isNullOrBlank()
final blank = s == null || s.trim() == '';
bool blank = s?.trim()?.isEmpty ?? true;
@import Foundation;
BOOL blank=![s stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceCharacterSet].length;
boolean blank = s==null || s.isBlank();
#include <ctype.h>
#include <stdbool.h>
bool blank = true;
for (const char *p = s; *p; p++) {
	if (!isspace(*p)) {
		blank = false;
		break;
	}
}
(define (empty-string? s)
  (= (string-length s) 0))

(define blank (empty-string? (string-trim s)))
blank := s isAllSeparators.
let blank = s.chars().all(|c| c.is_whitespace());
boolean blank = s == null || s.equals("") || s.matches("\\s+");
 blank = (s == nil or #string.gsub(s, "^%s*(.-)%s*$", "%1") == 0)