Page tree
Skip to end of metadata
Go to start of metadata

%RxReplaceStr function


The function replaces the predefined number of substrings in the input text, that are matching the specified regular expression, by another substring.

INT %RxReplaceStr(
   TEXT in Text, 
   TEXT in regExp,
   TEXT	in subStr,
   INT	in from := 1,
   INT	in count := 0
textText, in which will be replacement.
regExpRegular expression, which will be replaced in the input paremeter text.
substrSubstring, which will replace the found substring that mathes the regular expression.
fromIndex, from where to search input text (0 = from start) (optional input parameter).
countNumber of occurrences to be replaced (0 = all occurrences) (optional input parameter).

The function returns string, in which will be replaced count occurrences of regular expression regExp by substring substr, while input text will be searched from index from. If some of the input parameters is invalid, the function returns undefined value.


%RxReplaceStr("text some text",  "[a-z]+", "(X)")			;returns text: (X) (X) (X)
%RxReplaceStr("text some text",  "[a-z]+", "(X)", 1, 0)		;returns text: (X) (X) (X)
%RxReplaceStr("text some text",  "[a-z]+", "(X)", 1, 2)		;returns text: (X) (X) text
%RxReplaceStr("text some text",  "[a-z]+", "(X)", 2, 1)		;returns text: t(X) some text
%RxReplaceStr("text some text",  "[a-z]+", "(X)", 5, 1)		;returns text: text (X) text
%RxReplaceStr("text some text",  "[a-z]+", "(X)", 20, 0)	;returns text: text some text
%RxReplaceStr("text some text",  "[a-z]+", "(X)", 0, 20)	;returns text: (X) (X) (X)
Write a comment…