Skip to content

IfBlank ​

The IfBlank function checks the string specified by aValue1, and if it is blank, then the replacement value specified by aValue2 is put in its place.

If aValue1 is blank, it will return a vartype value of 258, representing a string.

A blank string is not the same as a string of blank spaces - a string containing blank spaces is not considered to be blank for the purposes of this function.

Please also refer to IfNull and IfEmpty under Variant Functions.

Declaration: Function IfBlank(const aValue1, aValue2 : string) : string;

Simple examples.

pascal
procedure ScriptEvent (var Value : variant);
var
  Str1, Str2, Str3 : string;
begin
  Str1 := '';
  Str2 := 'Hello';
  Str3 := IfBlank(Str1, Str2);                         //Replaces the blank string with "Hello"
  LogInfo(Str3);                                       //Returns 'Hello'
  LogInfo('');

  Str1 := '      ';
  Str2 := 'Hello AGAIN';
  Str3 := IfBlank(Str1, Str2);                          //Str1 is not considered to be BLANK
  LogInfo(Str3);                                        //Returns '        '
  LogInfo('');

  Str1 := '';
  LogInfo('Str1 = '+IntToStr(VarType(Str1)));            //BLANK string ariable returns 258
  Str2 := 'Winnie The Pooh';                             //Non blank
  LogInfo('Str2 = '+IntToStr(VarType(Str2)));            //Non-BLANK string variable returns 258
  LogInfo('');

  Str3 := IfBlank(Bla1, 'Param1 is BLANK');              //Str1 is BLANK
  LogInfo('Str3 = '+Str3);                               //Returns 'Param1 is BLANK'
  LogInfo('');

  Str3 := IfBlank(Str1, Str2 + ' + Piglet!');            //Str1 is BLANK
  LogInfo('Str3 = '+Str3);                               //Returns 'Winnie The Pooh + Piglet!'
  LogInfo('');

  Str3 := IfBlank('', 'Replacement value.');             //Param1 is empty
  LogInfo('Str3 = '+Str3);                               //Returns 'Replacement value.'
  LogInfo('');

  Str3 := IfBlank('    ', 'Param1 is BLANK');            //1st param holds blank spaces - so not blank
  LogInfo('Str3 = '+Str3);                               //Returns itself '      '   (blank spaces)

end;