Consultor Eletrônico



Kbase P139948: 4GL/ABL: How to replace the single quote character using the 4GL/ABL REPLACE Function?
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   10/06/2010
Status: Verified

GOAL:

4GL/ABL: How to replace the single quote character using the 4GL/ABL REPLACE Function?

GOAL:

How to replace a single tilde ~ character with a two tilde ~~ characters in a variable using the REPLACE Function?

GOAL:

What does the 4GL/ABL REPLACE Function do?

GOAL:

What is the syntax 4GL/ABL REPLACE Function?

FACT(s) (Environment):

All Supported Operating Systems
Progress 8.x
Progress 9.x
OpenEdge 10.x

FIX:

1. The 4GL/ABL REPLACE Function takes three INPUT CHARACTER PARAMETERS and returns a string with the specified substring replacements. In other words, it returns a transformation of the original string with all the occurrences of the from-string in it replaced with instances of the to-string.

For example, the expression: REPLACE ( "ABC", "B", "XXX") returns the string: "AXXXC". And the expression: REPLACE ( "ABCB", "B", "XXX") returns the string: "AXXXCXXX".
Similarly, the expression REPLACE ( "abc~~def", "~~", "~~~~") replaces the single tilde ~ character in the string 'abc~def' with two tilde ~~ characters and returns 'abc~~def'. Notice that the replace function here takes two tilde characters for each literal tilde ! character. The first ~ character to let Progress know that the next character should be taken literally and not as a special character and the second tilde ~ character that follows is the character that is to be taken as a literal.

2. The syntax of the REPLACE Function is:
REPLACE ( source-string , from-string , to-string )

Where:
The source-string parameter is the string to be transformed which can be any expression that evaluates to a string. And
The from-string parameter is the substring to replace if it exists in the source-string and which can be any expression that evaluates to a string. And
The to-string parameter is the replacement substring and which can be any expression that evaluates to a string
3. To replace the single quote character using the 4GL/ABL REPLACE Function, use the escape character tilde (~) before the single quote character to tell Progress/OpenEdge to read the following character, i.e. the single quote character, literally.
For example, the expression: REPLACE ( "Where is the Programmer's manual", "~'", "XXX") returns the string: "Where is the ProgrammerXXXs manual"
Similarly, the expression: REPLACE ( "Where is the Programmer's manual", CHR(39), "XXX") returns the same string: "Where is the ProgrammerXXXs manual" also.