Tech Tip: Split text by lines
PRODUCT: 4D | VERSION: 14.3 | PLATFORM: Mac & Win
Published On: June 4, 2015
Below is an example of seperating each line of text into an array element.
C_TEXT($1;$text) C_POINTER($2;$arrLines) If (Count parameters>=2) $text:=$1 $arrLines:=$2 $text:=$text+"\r\n" //add ending linebreak $pattern:="\r\n?|\n|<br/>" //find linebreaks $found:=True $start:=1 While ($found) $found:=Match regex($pattern;$text;$start;$pos;$len) If ($found) APPEND TO ARRAY($arrLines->;Substring($text;$start;$pos-$start)) $start:=$pos+$len End if End while End if |
Here is an example of splitting the following text:
After running the following code:
ARRAY TEXT($arrlines;0) UTIL_SPLIT_TEXT_BY_LINES($text;->$arrlines) |
The array $arrlines are filled with the following elements: