DSUBSTR: Extracting a Substring

How to:

If your configuration uses a DBCS code page, you can use the DSUBSTR function to extract a substring based on its length and position in the source string.


Top of page

x
Syntax: How to Extract a Substring
DSUBSTR(inlength, source_string, start, end, sublength, output)

where:

inlength

Integer

Is the length of the source string in bytes, or a field that contains the length. The string can have a mixture of DBCS and SBCS characters. Therefore, the number of bytes represents the maximum number of characters possible in the source string.

source_string

Alphanumeric

Is the string from which the substring will be extracted enclosed in single quotation marks, or the field containing the parent string.

start

Integer

Is the starting position (in number of characters) of the substring in the source string. If this argument is less than one or greater than end, the function returns spaces.

end

Integer

Is the ending position (in number of characters) of the substring. If this argument is less than start or greater than inlength, the function returns spaces.

sublength

Integer

Is the length of the substring, in characters (normally end - start + 1). If sublength is longer than end - start +1, the substring is padded with trailing spaces. If it is shorter, the substring is truncated. This value should be the declared length of output. Only sublength characters will be processed.

output

Alphanumeric

Is the field to which the result is returned, or the format of the output value enclosed in single quotation marks.



Example: Extracting a Substring

The following example extracts the 3-character substring in positions 4 through 6 from a 15-byte string of characters:


WebFOCUS