To string or not to string
Username:  
Password:
  > Home
> User Guide
v Reference
    > Introduction
    > CROFT
    v BEE Variables
       > BEE Variable Name
       o BEE Variable Value
       v BEE Conversions
          o Intrinsic Conversions
          o User-defined Conversions
          o To string or not to string
    > BEE Syntax
    > BEE Commands
    > Database Operation
    > Content Management
    > Objects and Classes
    > Interface with others
    o Glossary
> Portal Object
> Development Guide


Shortcuts
sys Class
debug Class
Intrinsic Conversions
>> Reference >> BEE Variables >> BEE Conversions >> To string or not to string <=  =>      <  1  >  
Rules to interpret string and array in conversions

Some intrinsic conversions are used to convert string to string and some array to array.  There are others that convert array to string as well.  While the structure (whether it is a string or an array) of the output is controlled by the conversion, the input is not.

If the input is in element form (string) and the conversion takes a string as input, it would be a simple string conversion.  If the input is in array form (element part missing) and the conversion takes an array as input, it would be a simple array conversion.

However, it is more complicated when the input is array form but the intrinsic conversion expects a string input, or when the input is a string but the intrinsic conversion expects an array.  For a user-defined conversion, the system cannot tell whether it expects a string or an array, which adds to the complications.

To take the complication further, the array form is commonly used as a simple variable and means its default element (the one indexed by blank), and they're indistinguishable in syntax.

Here is a table to summarise the situations and how they were handled (in sequence of precedence):

Input value

Conversion

How to handle

is an array
or simple variable

Examples:

class%name
"(array)..."
"(db)..."

expects an array

Convert the input as an array.

expects a string

The system will apply the conversion to each element in the input array one by one.  This automatically takes care of the case of a simple variable, in which the default element will be converted.

is user-defined

The system calls the user-defined function passing it the standard arguments.

is a string

Examples:

class%name:elem
class%name:
"(expr)..."

expects a string

Convert the input as a string

expects an array

The system will take the conversion as a user-defined function and passes the standard arguments to it accordingly.

is user-defined

The system calls the user-defined function passing it the standard arguments.

 

Please note that if a conversion can process both array and string, it is suggested to make the Input Value explicit array or string to avoid ambiguity.  For example:

var x = -1;

display "{x:|if:@value > 0,unknown}";

 

The BEE Variable "x" is specified as a string (x: instead of x).  Otherwise, the conversion "if" would be on the array of x, in which @value would not make sense, and the conversion would not work.  This magic string-making colon is useful even in variable-less value initialization such as "{:=(expr){a} + {b}|if:@value > 10,not even ten}".

Please also note that curly bracketed variables always evaluate to a string, even the conversion output an array (in which case, the default element will be used to expand the curly bracket).  If you really want to convert a string to an array, you need to use the "conv" parameter.

Example:

var myString = "abc";

var myArray = "{myString|strtoarr}";         // Got a blank

var myArray = "{myString}" conv=strtoarr;    // Got an array

 

Previous Page       Next Page

Accsoft Computer Technology Pty Ltd     ABN: 98 065 617 549
PO Box 892, Epping NSW 1710         Level 1, Epping Office Park, 242 Beecroft Rd, Epping NSW 2121, Australia
Tel: Sydney - (02)98691668     National - 1300-881668         Fax: (02)98691866
© Copyright 2003 Accsoft Computer Technology Pty Ltd