min, max Functions on Strings

Prev Next

Function Names

min abc, max abc, min abc ignore blanks, min abc ignore case, max abc ignore case, min abc ignore both, min string, max string, min string ignore blanks, min string ignore case, max string ignore case, min string ignore both

Description

These functions identify the minimum or maximum string values using alphabetic ordering rules based on UNICODE character codes. If cases are not ignored, then min( 'A', 'a' ) returns 'A' because 'A' has the smaller character code. If cases are ignored two values of the same letter with different casesare compared, then the first of the two letters will be used for comparing with the remaining parameters, or returned. Note: "AA" is greater than "A", and "A " is greater than "A".

  • The suffix min ... ignore blanks ignores comparing values against blanks as blanks are the most minimum string value and you may want to skip comparing these blank ones.
    Attention: Other functions with ending ... ignore blanks ignore all white spaces in the parameters, but this is not the case in this function.
  • In the case above, if all values are blank, then blank will be returned.
  • Function names containing string require the parameters to be string. Otherwise exceptions happen.
  • Function names containing abc will convert the parameters into strings before comparing them, e.g. Boolean true changes to string 'true', and numbers change to strings ('12' is bigger than '111').

Minimum Function Name Maximum Function Name Autom. Type conversion Description
min abc max abc Yes Picks minimum or maximum value provided
min string max string No "
min abc ignore case max abc ignore case Yes Ignore upper/lower case, and picks minimum or maximum value provided
min string ignore case max string ignore case No "
min abc ignore blanks --- Yes Picks minimum or maximum value provided, but ignores the blank ones
min string ignore blanks --- No "
min abc ignore both --- Yes Picks minimum or maximum value provided, but ignores the blank ones and ignores case
min string ignore both --- No "

Please note that equivalent conditional combination functions are also available for the function names listed above which allows you to pre-select specific parameters to include in the calculation using one or more comparisons .

Call as: function

Parameter count

Min 1

Parameters

No.TypeDescription
1, etc.
input
valid types All function parameters:

Same parameter passing principle is applied like other series functions such as add(), sub(), etc.
See Two parameter passing methods for series functions for details..

Return value

TypeDescription
string Result

Calculated value

Exceptions

Function names containing 'string' assert exceptions if values provided are not of type iteral

Examples

               echo( min abc ( 13, 100 ) ); // It's 100
               echo( max abc ( AH, ah, aH, Ah ) ); // Picks ah
               echo( max abc ignore case ( AH, ah, aH, Ah ) ); // Picks 1st parameter
               echo( min abc ( Abel, '', '', Beat, '' ) ); // Unpleasant outcome
               echo( min string ignore blanks ( Abel, '', '', Beat, '' ) ); // This one is better      
               echo( min string ignore both( Beat, Abel, ABEL, '' ) ); // Picks Abel (cases ignored)

Output

100
ah
AH

Abel
Abel
Try it yourself: Open LIB_Function_min_abc.b4p in B4P_Examples.zip. Decompress before use.

See also

min 123
max 123
min numeral
max numeral
min
max