Question

Is it possible to enter a multiline text/string literal in a 4D method? Something like:

C_TEXT($var)
$var:="""First Line
Second Line
Third Line"""

Using the triple-" here as they are being used in Python, just as example.

Was it helpful?

Solution

You could also do it that way in 4D v12 and above

C_TEXT($var)
$var:="First Line\r"+\
"Second Line\r"+\
"Third Line"

OTHER TIPS

I don't believe it is. Throughout our program we do something like this:

C_TEXT(<>CR)
C_TEXT($var)

<>CR:=Char(13) //carriage return

$var:="First Line" + <>CR + "Second Line" + <>CR + "Third Line"

We also have a linefeed: <>LF:=Char(10). We use IP variables that are defined during program startup for these characters and a few others, Tab comes to mind. You could use constants, but we've had some issues with those in the past so we try not to use them when possible.

You can also use a \n or \r within the text. In the debugger it will just show them all on one line with the \n and \r, but I believe it will display multiline (it does in an Alert()).

$var:="First Line\nSecond Line\nThird Line"

We choose the first way for readability and maintainability.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top