Omni Systems, Inc.

  

Mif2Go User's Guide, Version 33u53

  

Valid HTML 4.01!

 

Made with Mif2Go

27 Working with Mif2Go macros > 27.5 Using expressions in macros > 27.5.5 Specifying substrings in expressions


27.5.5 Specifying substrings in expressions

You can determine the number of characters in a macro variable, and use string operators to extract substrings from the value of the variable. Table 27-7 lists several of the string operators and shows how they are used in macro expressions.

See also:

§27.5.2 Understanding operands and operators

Table 27-4 Operators for HTML macro expressions

Table 27-7 String operators in macro expressions

Operator

Macro expression

Result of expression

Type

Value

length

($$string length)

Integer

Number of characters in $$string

char

($$string char N)

String

Nth character in $$string, counting from the left; the leftmost character is number 1

first

($$string first N)

String

First N characters of $$string

last

($$string last N)

String

Last N characters of $$string

before

($$string before $$str)

String

Substring that precedes the first (leftmost) occurrence of $$str in $$string

after

($$string after $$str)

String

Substring that follows the first (leftmost) occurrence of $$str in $$string

starts

($$string starts $$str)

Boolean

True if $$str is at the start of $$string

ends

($$string ends $$str)

Boolean

True if $$str is at the end of $$string

contains

($$string contains $$str)

Boolean

True if $$str occurs anywhere in $$string

trim first

($$string trim first N)

String

All but the first N characters of $$string

trim last

($$string trim last N)

String

All but the last N characters of $$string

For example, to trim off the first four characters of $$mystring:

<$$mystring = ($$yourstring trim first 4)>

If the value of $$yourstring is "makework", the value of $$mystring would be "work".

Implied value of second operand

If the second operand N is missing from an expression that uses one of the following operators, a value of 1 (one) is assumed for N:

char

first

last

trim first

trim last

For example, to select only the last character, you can omit the second operand:

<$$yourstring = ($$mystring last)>

If the value of $$mystring is "groceries", the value of $$yourstring would be "s".



27 Working with Mif2Go macros > 27.5 Using expressions in macros > 27.5.5 Specifying substrings in expressions