如何仅替换字符串的最后一个字符:
select REPLACE('this is the news with a þ','þ','__')
我得到的结果是:
__是__e news wi__ a __
编辑
服务器和数据库的排序规则是Latin1_General_CI_AS
我正在运行的实际查询是REPLACE(注意,’þ’,”)其中note是一个ntext列.重点是剥离刺字符,因为该字符后来在过程中用作列分隔符. (请不要建议更改分隔符,考虑到它的使用程度,这不会发生!)
我尝试使用N前缀,即使使用test select语句,结果如下:
解决方法
þ字符(ASCII和UNICODE值254)被称为“刺”,在某些语言中直接等同于:
>这里的角色技术信息:http://unicode-table.com/en/00FE/
>此处对该字符和排序规则的说明:http://userguide.icu-project.org/collation/customization.在“复杂裁剪示例”中搜索页面(通常为Control-F),您将看到以下内容:
The letter ‘þ’ (THORN) is normally treated by UCA/root collation as a separate letter that has primary-level sorting after ‘z’. However,in Swedish and some other Scandinavian languages,‘þ’ and ‘Þ’ should be treated as just a tertiary-level difference from the letters “th” and “TH” respectively.
如果您不希望þ等于th,则按如下方式强制进行二进制排序规则:
SELECT REPLACE(N'this is the news with a þ' COLLATE Latin1_General_100_BIN2,N'þ',N'__');
返回:
this is the news with a __