Work with CHARACTER data
- Last Updated: October 16, 2024
- 3 minute read
- OpenEdge
- Version 13.0
- Documentation
|
ABL provides many operators and functions for working with strings. All of these can be used with CHARACTER data, and most of these can also be used with LONGCHAR data.
| String functions and operators | Description |
|---|---|
| + Concatenation operator | Joins two character strings or expressions. |
| ASC function | Converts a character expression representing a single character into the corresponding ASCII (or internal code page) value, returned as an INTEGER. |
| BEGINS operator | Returns true if a string begins with a pattern. |
| CAPS function | Returns the uppercase version of a string. |
| CHR function | Converts an integer value to its corresponding character value. |
| COMPARE function | Compares two strings using a specified comparison operator or function. |
| FILL function | Generates a string made up of a character string that is repeated a specified number of times. |
| INDEX function | Searches the string for a substring, and if it is found, then returns the location of the substring. |
| LC function | Returns the lowercase version of a string. |
| LEFT-TRIM function | Removes characters from the beginning of a string, including leading blanks. |
| LENGTH function | Returns the length of the string. |
| MATCHES operator | Performs a wildcard match for a string within another string. By
default MATCHES is not case
sensitive. |
| OVERLAY statement | Inserts content from a specified expression into a field or variable replacing existing characters, bytes, or columns. |
| R-INDEX function | Returns an INTEGER value that indicates the position of the target string within the source string. In contrast to the INDEX function, R-INDEX performs the search from right to left. |
| REPLACE function | Returns a string with specified substring replacements. The data type of the returned value matches the data type of the expression passed to the function. |
| RIGHT-TRIM function | Removes characters from the end of a string, including trailing blanks. |
| STRING function | Converts a value of another data type into a character value. |
| SUBSTITUTE function | Returns a character string that is made up of a base string plus the substitution of arguments in the string. |
| SUBSTRING function | Returns a substring of a string based on the locations specified in the string. |
| TRIM function | Removes characters from the beginning or end of a string, including leading or trailing blanks. |
For additional information, see ABL string manipulation functions.
The next sections discuss how to use the concatenation operator (+) and
the SUBSTITUTE, REPLACE, and STRING functions. These are
commonly used for string manipulation. For more information about
the other functions listed, click on the links.
.
Concatenation operator (+)
You can combine character strings by concatenating them. Concatenation means putting two or more strings together in sequence. For example, the string "PRO" concatenated with the string "GRESS" becomes "PROGRESS".
|
If you want spaces or punctuation to appear between string values, then you must explicitly include them. For example, to display a person's full name, you might write the following code:
|
Running the code produces the following output:
|
SUBSTITUTE function
The SUBSTITUTE function returns a character string that is made up of a base string plus the substitution of parameter values in the string. This function allows you to use a single string in place of concatenated strings.
|
new-string- The string returned by the
SUBSTITUTEfunction. base-string- A character string optionally containing substitution
parameters of the form
&n, where n is an integer between 1 and 9, inclusive. arg- A constant, field name, variable, or expression that results in a character string value. These values replace substitution parameters in base-string.
The following example code uses substitution rather than
concatenation, but produces the same output as the previous example. In this
example, firstName replaces &1; middleInitial replaces &2; and
lastName replaces &3.
|
REPLACE function
You can use the REPLACE function to replace characters in a variable with an expression.
The syntax for the REPLACE
function is:
new-string = REPLACE(source-string, from-string,
to-string)
new-string- The string returned by the
REPLACEfunction. source-string- Specifies the base string to make replacements in. The
source-string parameter can be any
expression that evaluates to a string. The
REPLACEfunction does not change the value of source-string itself, unless new-string and source-string refer to the same variable. from-string- Specifies the substring to replace. The from-string parameter can be any expression that evaluates to a string. Each occurrence of from-string within source-string is replaced.
to-string- Specifies the replacement substring. The to-string parameter can be any expression that evaluates to a string. Each occurrence of from-string in source-string is replaced by to-string.
Example: Replace a text string
REPLACE function changes the
separator from a comma to a bar surrounded by spaces, for better
readability.
|
|
|