How to: |
The SUBSTV function extracts a substring from a string and is similar to SUBSTR. However, the end position for the string is calculated from the starting position and the substring length. Therefore, it has fewer parameters than SUBSTR. Also, the actual length of the output field, if it is an AnV field, is determined based on the substring length.
SUBSTV(upper_limit, source_string, start, sub_limit, output_format)
where:
Integer
Is the limit for the length of the source_string.
Alphanumeric of type An or AnV
Is the character string that contains the substring you want to extract. If it is a field of type AnV, its length is taken from the length-in-bytes of the field. If the upper_limit is smaller than the length, the source_string is truncated to the upper_limit. The final length value determined by this comparison is referred to as p_length (see output_format for related information).
Integer
Is the starting position of the substring in the source_string. Note that the starting position can exceed the source_string length and doing so will result in spaces being returned.
Integer
Is the limit for the length of the substring. The end position of the substring is end = start + sub_limit - 1. Note that the ending position can exceed the source_string length depending on the provided values for start and sub_limit.
Alphanumeric of type AnV or An
If the format of output_format is AnV, the actual length, outlen, is computed as follows from the values for end, start, and p_length (see source_string for related information):
If end > p_length or end < start, then outlen = 0; otherwise, outlen = end - start + 1.
SUBSTV extracts the first three characters from the TITLEV and stores the result in a column with the format A20V:
SUBSTV(39, TITLEV, 1, 3, 'A20V')
For SMURFS, the result is SMU.
For SHAGGY DOG, the result is SHA.
iWay Software |