Previous Topic: INITIATE StatementNext Topic: LIST Statement


INVERT Statement

The INVERT statement reverses the order of characters in a given alphanumeric field or alphanumeric group.

This statement has the following format:

INVERT {alpha_field | alpha_group}

Example

The following example shows how you can use INVERT in text processing to find the start of the last word in a sentence. W‑WORK is defined as type V for a variable length field.

SET W_SENTENCE = 'THIS IS A SENTENCE
'SET W_WORK = $TRIM(W_SENTENCE,RIGHT=' ')
INVERT W_WORK
SET N = $INDEX(W_WORK,SEARCH= ' ')
SET W_LAST_WORD = $SUBSTR(W_WORK,LEN=(N ‑ 1 ))
INVERT W_LAST_WORDSET W_SENTENCE = $SUBSTR(W_WORK,START=(N + 1))
INVERT W_SENTENCE

As a result of the example, W_LAST_WORD contains 'SENTENCE' and W_SENTENCE contains 'THIS IS A'.