在考慮我的問題,我想出了這個 - 這似乎有點大材小用,但我想不出任何其他方式:
DECLARE @text NVARCHAR(MAX) = 'Has many applications. The price is low. The quality is good. Availability is widespread.'; --Set text.
DECLARE @text2 NVARCHAR(MAX) = LEFT(@text,CHARINDEX('.',@text)); --Extract first sentence.
PRINT @text2; --Print first sentence.
SET @text = RIGHT(@text,LEN(@text)-LEN(@text2)); --Subtract @text2 from @text - will include the space at the begining that was after the first full stop.
WHILE LEN(@text) >0
BEGIN
SET @text = RIGHT(@text, LEN(@text)-1);--Take of the space that after the full stop in previous iteration of @text.
SET @text2 = LEFT(@text,CHARINDEX('.',@text));--Exract the 'new' first sentence.
PRINT @text2;
SET @text = RIGHT(@text,LEN(@text)-LEN(@text2)); --Subtract @text2 from @text - will include the space at the begining that was after the first full stop.
END;
其他建議都歡迎。
編輯 - John Cappelletti的出色答案促使我改善自己。它現在不會被小數點抓住,也可以識別回車。將有一個不同的應用程序,但認爲包括任何尋找任何解決方案的任何人可能是有用的。
DECLARE @text NVARCHAR(MAX) =
'I would like to pay £22.99. Has many applications.
£45.00 is good value. The price is low. The quality is good.
Availability is widespread. Good value at £5.00.' --Set text.
DECLARE @text2 NVARCHAR(MAX) = LEFT(@text,CHARINDEX('. ',@text)) --Extract first sentence.
PRINT @text2 --Print first sentence.
SET @text = RIGHT(@text,LEN(@text)-LEN(@text2)) --Subtract @text2 from @text - will include the space at the begining that was after the first full stop.
WHILE LEN(@text) >0
BEGIN
SET @text = RIGHT(@text, LEN(@text)-1)--Take off the space that after the full stop in previous iteration of @text.
SET @text2 = IIF(LEN(LEFT(@text,CHARINDEX('. ',@text)))=0, LEFT(@text,CHARINDEX('.',@text)+LEN(RIGHT(@text, LEN(@text)-LEN(LEFT(@text,CHARINDEX('.',@text)))))),LEFT(@text,CHARINDEX('. ',@text)))--Extract the new first sentence.
PRINT @text2
SET @text = RIGHT(@text,LEN(@text)-LEN(@text2)) --Subtract @text2 from @text - will include the space at the begining that was after the first full stop.
END
完美!我沒有想過小數位。所有我必須添加的是:IIF(右(Key_value,1)='。',Key_value,Key_value +'。')以確保所有行在結尾處回到完全停止狀態。 – SteelyDanFan
樂意幫忙。我過去曾被那條狗咬過。乾杯。 –
今天玩了這個 - 行'Set @String = Replace(@ String,@ delimeter + @ delimeter,@ delimeter)'是做什麼的? – SteelyDanFan