2016-02-22 117 views
0

我有一个数据库字段,例如字符串这样水晶报表找到一个字符串的第3个字

oh the sea OToole was right 
I like ramen but 
Rowing like a Blue but not an artist 

他们是用空格分隔实际的话

我想找到提取前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和阵列的大小

任何见解都比欢迎

+0

我想创建一个SQL命令来做到这一点的......不过好像连更糟糕,因为我需要创建功能等... -_- –

+0

我只有两个领域,因此你得到错误 – Siva

+0

嗨@Siva,你说的2个领域? –

回答

1
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]," ") 
+0

这种情况实际上为我工作'ubound(拆分({tbname.field1}))<3或ubound(拆分({tbname.field1}))> 0'我试图编辑您的答案但'权力'负责没有看到它适当的:) –

+0

我看到了建议,但它不会让我批准它。我想我没有足够的声望! – CoSpringsGuy

+0

但你可以改变你的答案:)(如果你想,当然) –

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); 
+0

没有工作时出现错误。但无论如何,非常感谢您的帮助 –