2016-02-22 56 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

沒有工作時出現錯誤。但無論如何,非常感謝您的幫助 –