The &STRING String Function - Ultramarine.com The &STRING String Function

Another function for dealing with strings is:


     &STRING(ACTION, STRING(1), STRING(2), ..... STRING(n))

Here ACTION defines what you want the function to do, and STRING(i) are the strings. STRING(1) is the "basic string" and the others may be used for additional operational data, depending on ACTION. Here, the valid forms of the function are:

     &STRING(SUBSTR,    STRING(1), BCN, ECN)
     &STRING(BEFORE,    STRING(1), DELIM )
     &STRING(AFTER,     STRING(1), DELIM )
     &STRING(MATCH,     STRING(1), STRING(2) )
     &STRING(NULL,      STRING(1) )
     &STRING(O_NUMBER,  STRING(1), NUMBER )
     &STRING(OVERLAY,   STRING(1), STRING(2) )
     &STRING(REVERSE,   STRING(1), STRING(2), .....  )
     &STRING(N_EXTRACT, WORD, NUMBER, STRING(3), ....  )
     &STRING(REPEAT,    WORD, NUMBER )

For SUBSTR, the result will be the characters BCN through ECN of the input string, STRING(1). For BEFORE, the result will be the characters of STRING(1) starting at the beginning of the string through the character before the character DELIM. For AFTER, the result is the last portion of STRING(1), beginning with the character after the last occurrence of DELIM. MATCH returns a value of .TRUE., if STRING(1) matches STRING(2), and .FALSE. if it does not. The function NULL returns a value of .TRUE. if STRING1 is null, and a value of .FALSE. otherwise. The function O_NUMBER "overlays" the integer, NUMBER, on the string, STRING(1), starting at the end. For example if STRING(1) is N00000000 and number is 3333, then the returned string will be N00003333. The function OVERLAY works in a similar fashion, except the values here are characters. The command &STRING(OVERLAY 12345678 ABCDE) will return a value of 123ABCDE, for instance. Both of these functions are useful for building names, which can be used to automate the creation of various analytical models. The function REVERSE will reverse the tokens of STRING1. N_EXTRACT will return NUMBER numbers from STRING(3), starting at the token immediately following the word WORD. If there are not NUMBER numbers, zeros are returned; i.e. first, WORD is found in the string, and the next token is checked. If it is not a number or if WORD is not found, then NUMBER zeros are returned. If this token is a number, then the first value returned is set to the number and the next token is checked. This process is repeated until either NUMBER numbers have been found, or a non-number terminates the process. Finally, the function REPEAT will return a string with NUMBER occurrences of STRING.