2017-09-27 49 views
1

如何將包含句子的字符串轉換爲一系列單詞,例如:下面的字符串轉換爲:在Red/Rebol中將長字符串轉換爲單個單詞

str: "This is a sentence with some words" 

一系列的:

["This" "is" "a" "sentence" "with" "some" "words"] 

似乎有分裂功能Rebol3Rebol2沒有這種功能。

我試圖在與解析的代碼,但它不工作:

str: "This is a sentence with some words" 
strlist: [] 
parse str [ 
    some got: " " (append strlist got) ] 

錯誤是:

** Script Error: Invalid argument: got 

如何才能實現這一目標(與解析的方法會更好)?

+1

在Rebol 2中,你使用PARSE進行分割:'parse「foo bar baz」「」' – rgchris

+0

它是如何工作的? – rnso

+1

便利功能,不建議或可用rebol3或紅色 –

回答

2

在雷博爾2,這將是:

str: "This is a sentence with some words" 
parse str none 

導致:

["This" "is" "a" "sentence" "with" "some" "words"] 

正如您的文章,the documentation的評論中提到。解析有兩種模式,其中之一是字符串分割。

Rebol 3,split將工作。

+0

您也可以添加如何以紅色語言完成。 – rnso

2

這將是

split str " " 

裏劈的功能。第一個參數是你的字符串,第二個分隔符。

+0

這在Rebol 2.7.8中不起作用。 '**腳本錯誤:split沒有值' – rnso

+1

找不到Rebol 2的文檔。在Rebol 3中應該可以正常工作:http://www.rebol.com/r3/docs/functions/split.html – Shultc