Tech Tip: Finding all expressions in a styled text
PRODUCT: 4D | VERSION: 15 | PLATFORM: Mac & Win
Published On: January 7, 2016
Below is an utility method to get all expressions and their value in a styled text object.
C_TEXT($1;$text) C_POINTER($2;$arrExpressions) C_POINTER($3;$arrExpVals) C_LONGINT($type;$start;$end;$startBlock;$endBlock) C_TEXT($expression;$expVal) C_BOOLEAN($done) If (Count parameters>=3) $text:=$1 $arrExpressions:=$2 $arrExpVals:=$3 $done:=False $start:=ST Start text $end:=ST End text While (Not($done)) $type:=ST Get content type($text;$start;$end;$startBlock;$endBlock) If ($type=ST Expression type) $expression:=ST Get expression($text;$startBlock;$endBlock) $expVal:=ST Get text($text;$startBlock;$endBlock) $expVal:=ST Get plain text($expVal;ST 4D Expressions as values) APPEND TO ARRAY($arrExpVals->;$expVal) APPEND TO ARRAY($arrExpressions->;$expression) End if $start:=$endBlock $end:=$endBlock+1 If ($startBlock>=$endBlock) $done:=True End if End while End if |
Example:
The following text below has several expressions inserted into it.
12/04/15 08:58:16 Dear Mr. Ford, My name is Joe Smith... Kind Regards, Joe Smith Investment Specialist |
The expressions are shown below:
Current date Current time Dear [Contact]Salutation, My name is <>YourName_t... Kind Regards, <>YourName_t <>YourTitle_t |
Running the following code will return the expressions and values into two arrays:
ARRAY TEXT($arrExpressions;0) //array to contain expressions ARRAY TEXT($arrExpVals;0) ST_GET_EXPRESSIONS (vText;->$arrExpressions;->$arrExpVals) |
The results are shown below: