Omni Systems, Inc.

  

Mif2Go User's Guide, Version 55

  

Valid HTML 4.01!

 

Made with Mif2Go

28 Working with macros > 28.6 Using expressions in macros > 28.6.5 Specifying substrings in expressions


28.6.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 28-7 lists several of the string operators and shows how they are used in macro expressions.

See also:

§28.6.2 Understanding operands and operators

Table 28-4 Operators for HTML macro expressions

Table 28-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

replace with

($$string replace " " with "_")

String

Each instance of first operand is replaced with second operand

upper

($$string upper)

String

$$string is all uppercase

lower

($$string lower)

String

$$string is all lowercase

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”.



28 Working with macros > 28.6 Using expressions in macros > 28.6.5 Specifying substrings in expressions