Crystal reports 基于回车的水晶分割字符串

Crystal reports 基于回车的水晶分割字符串,crystal-reports,crystal-reports-2010,Crystal Reports,Crystal Reports 2010,我有一个类似这样的字段,我只想在Crystal report上显示第一个/最新的条目: 2018年01月05日00:00:00下午备注 2018年1月4日00:00:00更多注释 2018年1月3日下午00:00:00更多注释 这是我一直在尝试使用的代码,但我遇到了一个错误“下标必须介于1和数组大小之间”。有人能帮我指出正确的方向吗 stringvar array csl; stringvar return; csl:=split({table.field},chr(13)); //csl[1]

我有一个类似这样的字段,我只想在Crystal report上显示第一个/最新的条目:

2018年01月05日00:00:00下午备注

2018年1月4日00:00:00更多注释

2018年1月3日下午00:00:00更多注释

这是我一直在尝试使用的代码,但我遇到了一个错误“下标必须介于1和数组大小之间”。有人能帮我指出正确的方向吗

stringvar array csl;
stringvar return;
csl:=split({table.field},chr(13));
//csl[1]
if isnull({table.field}) then return:= ""
else return:=csl[1];
return;

该错误的原因可能是因为在
拆分之后检查null

我通常尽量避免在Crystal报告中使用数组/变量。主要是因为不能对包含变量的公式分组或使用聚合函数

下面是一个使用字符串函数的解决方案:

第一个条目

If InStr({table.field}, chr(13)) > 0 Then
    Left({table.field}, InStr({table.field}, chr(13)))
Else
    {table.field}
If InStrRev({table.field}, chr(13)) > 0 Then
    Right({table.field}, Len({table.field}) - InStrRev({table.field}, chr(13)))
Else
    {table.field}
If InStr(InStr({@table.field}, chr(13))+1,{@table.field}, chr(13)) > 0 Then
    Left({@table.field}, InStr(InStr({@table.field}, chr(13))+1, {@table.field}, chr(13)))
Else
    {@table.field}
If InStrRev({@table.field}, chr(13), InStrRev({@table.field}, chr(13))+1) > 0 Then
    Right({@table.field}, Len({@table.field}) - InStrRev({@table.field}, chr(13),InStrRev({@table.field}, chr(13))-1))
Else
    {@table.field}
最后一项

If InStr({table.field}, chr(13)) > 0 Then
    Left({table.field}, InStr({table.field}, chr(13)))
Else
    {table.field}
If InStrRev({table.field}, chr(13)) > 0 Then
    Right({table.field}, Len({table.field}) - InStrRev({table.field}, chr(13)))
Else
    {table.field}
If InStr(InStr({@table.field}, chr(13))+1,{@table.field}, chr(13)) > 0 Then
    Left({@table.field}, InStr(InStr({@table.field}, chr(13))+1, {@table.field}, chr(13)))
Else
    {@table.field}
If InStrRev({@table.field}, chr(13), InStrRev({@table.field}, chr(13))+1) > 0 Then
    Right({@table.field}, Len({@table.field}) - InStrRev({@table.field}, chr(13),InStrRev({@table.field}, chr(13))-1))
Else
    {@table.field}

编辑 要获得第二行,您必须执行两次
InStr
/
InStrRev

第一个条目

If InStr({table.field}, chr(13)) > 0 Then
    Left({table.field}, InStr({table.field}, chr(13)))
Else
    {table.field}
If InStrRev({table.field}, chr(13)) > 0 Then
    Right({table.field}, Len({table.field}) - InStrRev({table.field}, chr(13)))
Else
    {table.field}
If InStr(InStr({@table.field}, chr(13))+1,{@table.field}, chr(13)) > 0 Then
    Left({@table.field}, InStr(InStr({@table.field}, chr(13))+1, {@table.field}, chr(13)))
Else
    {@table.field}
If InStrRev({@table.field}, chr(13), InStrRev({@table.field}, chr(13))+1) > 0 Then
    Right({@table.field}, Len({@table.field}) - InStrRev({@table.field}, chr(13),InStrRev({@table.field}, chr(13))-1))
Else
    {@table.field}
最后一项

If InStr({table.field}, chr(13)) > 0 Then
    Left({table.field}, InStr({table.field}, chr(13)))
Else
    {table.field}
If InStrRev({table.field}, chr(13)) > 0 Then
    Right({table.field}, Len({table.field}) - InStrRev({table.field}, chr(13)))
Else
    {table.field}
If InStr(InStr({@table.field}, chr(13))+1,{@table.field}, chr(13)) > 0 Then
    Left({@table.field}, InStr(InStr({@table.field}, chr(13))+1, {@table.field}, chr(13)))
Else
    {@table.field}
If InStrRev({@table.field}, chr(13), InStrRev({@table.field}, chr(13))+1) > 0 Then
    Right({@table.field}, Len({@table.field}) - InStrRev({@table.field}, chr(13),InStrRev({@table.field}, chr(13))-1))
Else
    {@table.field}

马特,你真是太棒了,这真是太棒了!但是,我搞砸了。显然,第一行有日期、时间,下一行有注释,所以我实际上也需要下一行。有什么想法吗?非常感谢!我已经接受了你的回答。