How to insert a line break in a StringVar in Crystal Reports
Asked Answered
G

4

9

How do I enter a line break (or other non-text characters usually solved with escape characters) in a StringVar in Crystal Reports?

Wanted output:

line 1
line 2

I've tried StringVar s := "line 1 \n line 2";, but that does not work.

Get answered 29/8, 2012 at 11:40 Comment(0)
R
9

It may not be much of an improvement, but you could build a string-formatting, custom function:

// sf()
Function (Stringvar text)

    Stringvar Array keys := ["\n"];
    Stringvar Array values := [Chr(10)+Chr(13)];

    Numbervar i;

    For i := 1 to Ubound(keys) do (
        text := Replace(text, keys[i], values[i])
    );

    text;

//{@ text}
sf("line 1 \n line 2")

This would offer you some extensibility should you need to support additional escape sequences.

Rohn answered 29/8, 2012 at 12:45 Comment(1)
Overkill for my task, but a nice general and flexible solution.Get
B
12

i have simply used following code for line break

"This formula field " + ChrW(13) + " contains a line break!"

Brandiebrandise answered 28/10, 2014 at 8:26 Comment(0)
R
9

It may not be much of an improvement, but you could build a string-formatting, custom function:

// sf()
Function (Stringvar text)

    Stringvar Array keys := ["\n"];
    Stringvar Array values := [Chr(10)+Chr(13)];

    Numbervar i;

    For i := 1 to Ubound(keys) do (
        text := Replace(text, keys[i], values[i])
    );

    text;

//{@ text}
sf("line 1 \n line 2")

This would offer you some extensibility should you need to support additional escape sequences.

Rohn answered 29/8, 2012 at 12:45 Comment(1)
Overkill for my task, but a nice general and flexible solution.Get
G
4

I've found a functional, albeit not code aesthetical, solution:

StringVar s := "line 1" + chr(10) + chr(13) + "line 2";
Get answered 29/8, 2012 at 11:40 Comment(0)
R
0

You can pass it from the database itself with char(13) in SQL Server Management Studio 15.0.18390.0. Example: SELECT I.Name + char(13) + I.Name DISCRPIPTION from Items I.
Result in Crystal Report:-

enter image description here

Remus answered 3/5, 2023 at 11:6 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.