Return to String Function Index
String Function Syntax and Examples
REPLACE( )The REPLACE() function replaces a substring within a string.
Syntax:
REPLACE(string,string-to-find,string-to-replace [,count [,[CASEINSENS | 0] | [CASESENS | 1] ] ] )
where:
- string is any string or string expression that contains string-to-find. If an empty string argument ( ' ', length=0) is included, the function returns an empty string.
- string-to-find is the substring to be replaced. If an empty string-to-find argument ( ' ', length=0) is included, the function returns all of string.
- string-to-replace is the string that will replace string-to-find. If an empty string-to-replace argument ( ' ', length=0) is included, the function returns all of string. If an empty string-to-replace is included ( ' ', length=0), the function removes all occurrences of string-to-find.
- The optional count argument is an integer specifying the number of replacements to be made (that is, the number of occurrences of string-to-find to be replaced, counting from left to right).
- The optional CASEINSENS | CASESENS argument determines whether the comparison is to be case-sensitive (cases must match) or case-insensitive. The CASEINSENS and CASESENS arguments can be replaced by 0 and 1, respectively. By default, NDL++ searches are case-sensitive.
Example:
input: samplestring
IMPORT @sample.dat
{RECORD
{
field1 *\r\n
}
schema1.table1
{
col1 REPLACE(field1,'sample','my')
col2 REPLACE(field1,'string','data')
col3 REPLACE('','sample','my')
col4 REPLACE(field1,'','my')
col5 REPLACE(field1,'sample','')
col6 REPLACE(field1,'s','',1)
}}
Results:
schema1.table1.col1 mystring schema1.table1.col2 sampledata schema1.table1.col3 ''
(empty string, length=0)schema1.table1.col4 samplestring schema1.table1.col5 string schema1.table1.col6 amplestring
Return to String Function Index