如何仅替换字符串的最后一个字符:
select REPLACE('this is the news with a þ', 'þ', '__')
我收到的结果是:
__is is __e news wi__ a __
编辑: 服务器和数据库的排序规则为Latin1_General_CI_AS。
我实际运行的查询是
REPLACE(note, 'þ', '')
,其中note
是一个ntext
列。重点是要去掉thorn字符,因为该字符稍后会用作列分隔符。(请不要建议更改分隔符,考虑到其使用程度,这种情况是不可能发生的!)我尝试过使用
N
前缀,即使是在测试选择语句中,以下是结果:
![Still broken!](https://istack.dev59.com/KAEA2.webp)
N
。SELECT REPLACE(N'this is the news with a þ', N'þ', N'__');
this is the news with a __
。 - codeulike