string 如何在 Crystal Reports 的 StringVar 中插入换行符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12177102/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 01:34:24  来源:igfitidea点击:

How to insert a line break in a StringVar in Crystal Reports

stringcrystal-reportsescaping

提问by LapplandsCohan

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

如何在 Crystal Reports 的 StringVar 中输入换行符(或其他通常用转义字符解决的非文本字符)?

Wanted output:

想要的输出:

line 1
line 2

线 1
线 2

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

我试过了StringVar s := "line 1 \n line 2";,但这不起作用。

回答by Pranjal Jain

i have simply used following code for line break

我只是使用以下代码进行换行

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

“此公式字段” + ChrW(13) + “ 包含换行符!”

回答by craig

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.

如果您需要支持额外的转义序列,这将为您提供一些可扩展性。

回答by LapplandsCohan

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

我找到了一个功能性的,虽然不是代码美学的解决方案:

StringVar s := "line 1" + chr(10) + chr(13) + "line 2";