Crystal 报告查找字符串的前 3 个单词
Crystal Reports find the first 3 words of a string
我有一个包含这样字符串的数据库字段
oh the sea OToole was right
I like ramen but
Rowing like a Blue but not an artist
它们是用 space
分隔的实际单词
我要查找提取前3个字
结果如下
oh the sea
I like ramen
Rowing like a
我尝试了以下方法
ExtractString({tbname.field1},""," ") & " " & ExtractString({tbname.field1}," "," ") & ExtractString({tbname.field1}," "," ")
它对前两个字段有效,但对第二个字段无效
下面这个我也试过了
split({tbname.field1}, " ")[1] & " " & split({tbname.field1}, " ")[2]
& " " & split({tbname.field1}, " ")[3]
它给我一个错误,说索引必须在 1 和数组大小之间
欢迎任何见解
** 经过编辑以反映数据包含在一行中,而不是 3 行中
尝试:
// defined delimiter
Local Stringvar CRLF := Chr(10)+Chr(13);
// split CRLF-delimited string into an array
Local Stringvar Array rows := Split({Command.WORDS}, CRLF);
// the results of all the work
Local Stringvar Array results;
// process each 'row'
Local Numbervar i;
for i := 1 to ubound(rows) do (
// increment the array, then add first 3 words
Redim Preserve results[Ubound(results)+1];
results[ubound(results)]:=Join(Split(rows[i])[1 to 3]," ")
);
// create CRLF-delimited string
Join(results, CRLF);
if ubound(Split({tbname.field1})) < 3 then
Join(Split({tbname.field1})[1 to ubound(Split({tbname.field1}))]," ")
else Join(Split({tbname.field1})[1 to 3]," ")
我有一个包含这样字符串的数据库字段
oh the sea OToole was right
I like ramen but
Rowing like a Blue but not an artist
它们是用 space
分隔的实际单词我要查找提取前3个字
结果如下
oh the sea
I like ramen
Rowing like a
我尝试了以下方法
ExtractString({tbname.field1},""," ") & " " & ExtractString({tbname.field1}," "," ") & ExtractString({tbname.field1}," "," ")
它对前两个字段有效,但对第二个字段无效
下面这个我也试过了
split({tbname.field1}, " ")[1] & " " & split({tbname.field1}, " ")[2]
& " " & split({tbname.field1}, " ")[3]
它给我一个错误,说索引必须在 1 和数组大小之间
欢迎任何见解
** 经过编辑以反映数据包含在一行中,而不是 3 行中
尝试:
// defined delimiter
Local Stringvar CRLF := Chr(10)+Chr(13);
// split CRLF-delimited string into an array
Local Stringvar Array rows := Split({Command.WORDS}, CRLF);
// the results of all the work
Local Stringvar Array results;
// process each 'row'
Local Numbervar i;
for i := 1 to ubound(rows) do (
// increment the array, then add first 3 words
Redim Preserve results[Ubound(results)+1];
results[ubound(results)]:=Join(Split(rows[i])[1 to 3]," ")
);
// create CRLF-delimited string
Join(results, CRLF);
if ubound(Split({tbname.field1})) < 3 then
Join(Split({tbname.field1})[1 to ubound(Split({tbname.field1}))]," ")
else Join(Split({tbname.field1})[1 to 3]," ")