我有一个类似的文本:句子一。第二句。第三句。
我希望它是:
我想我可以替换
'.'
与 '.' + char(10) + char(13)
,但是我该如何处理子弹?如果手动打印,'•' 字符可以正常工作,我只是不知道如何将每个句子(包括第一个句子)加注。
最佳答案
-- Initial string
declare @text varchar(100)
set @text = 'Sentence one. Sentence two. Sentence three.'
-- Setting up replacement text - new lines (assuming this works) and bullets ( char(149) )
declare @replacement varchar(100)
set @replacement = '.' + char(10) + char(13) + char(149)
-- Adding a bullet at the beginning and doing the replacement, but this will also add a trailing bullet
declare @processedText varchar(100)
set @processedText = char(149) + ' ' + replace(@text, '.', @replacement)
-- Figure out length of substring to select in the next step
declare @substringLength int
set @substringLength = LEN(@processedText) - CHARINDEX(char(149), REVERSE(@processedText))
-- Removes trailing bullet
select substring(@processedText, 0, @substringLength)
我在这里测试过 - https://data.stackexchange.com/stackoverflow/qt/119364/我应该指出在 T-SQL 中这样做似乎不正确。 T-SQL 用于处理数据;任何特定于演示文稿的工作都应该在调用此 T-SQL(C# 或您使用的任何东西)的代码中完成。
关于sql - 在每个句子之前打印项目符号 + 在每个句子之后换行 SQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8290396/