是否有可能加入一個正則表達式的數組元素?如果是這樣,我該如何達到這些要求?加入數組元素與正則表達式
- 每個元素都應該用間距字符連接,除非它是一個空元素。
- 空數組元素應當與一個新行字符(
\n
)接合。
這意味着,這樣的:
["Hello, this is a sentence.", "This is another sentence.", "", "", "Then, there are 2 new lines.","","Then just one new line."]
應與.join
被轉換成這樣的:
Hello, this is a sentence. This is another sentence.
Then, there are 2 new lines.
Then just one new line.
幾乎可以正常工作。我仍然不知道爲什麼它會在所有句子的開頭添加空格字符。 – andufo
@andufo對不起,我沒看出來。固定。 –
仍然有當句子沒有他們之間的換行加入一些問題,但你給我的主要想法。我會盡力從那裏拿走它。謝謝! – andufo