Home page  
Help >
DDL Command SUBSTITUTE
Version 7.11
DDL Command SUBSTITUTE SUBSTITUTE

The SUBSTITUTE command is used to make string changes to the content of a variable.

Syntax:
SUBSTITUTE/options %v /oldstring/newstring/... /oldstring/newstring/

Notation standards Options Answers

Options:
A -Change all occurrences of "old string" to "new string"
U -Make the substitutions case-insensitive.
X -Suppress the command response.
Y -Do not alter the command answer cells.

Answers:
Ctl.Ans1 -Number of characters in the new value in the variable.
Ctl.Ans2 -Number of substitutions performed.
Ctl.Ans3 -Zero. .

Notes:
SUBSTITUTE can be abbreviated SUB.

You do not have to use slash (/) as the delimiter used to separate "old string" from "new string." You can use any character, such as semicolon (;), or period (.), or colon (:), or tilde (~) as the delimiter. For example:

Suppose you have a variable named %YY that contains the value aabbaa.

SUB %yy /bb/ggg/

causes the value to become aagggaa. The above command could also have been stated as:

sub %yy ;bb;ggg;

and would achieve the same result. The rule for delimiters is that the first character encountered after the variable name is the delimiter character that will be used to separate the two strings. The idea is to pick a delimiter that is not part of either the "old" or "new" strings that you are about to specify.

The default behavior of the SUBSTITUTE command is that it performs the substitution for the first occurrence of "old string" that it encounters. If you want it to perform the substitution for all occurrences, you must specify the A option. For example, lets say %yy contains aagggaa.Then:

sub %yy /aa/ww/ -would produce wwgggaa

sub/a %yy /aa/ww/ -would produce wwgggww

Also, substitutions are case sensitive unless you use the U option. For example, suppose %xx contains AaBbCc. Then:

sub %xx /a/w/ -would produce AwBbCc

sub/u %xx /a/w/ -would produce waBbCc

sub/au %xx /a/w/ -would produce wwBbCc

Copyright © 2019 , WhamTech, Inc.  All rights reserved. This document is provided for information purposes only and the contents hereof are subject to change without notice. Names may be trademarks of their respective owners.