How do I replace only the last character of the string:
select REPLACE(\'this is the news with a þ\', \'þ\', \'__\')
The result I\'m gettin
This might work for you:
DECLARE @text NVARCHAR(1000) = N'this is the news with a þ';
DECLARE @find NVARCHAR(1000) = N'þ';
DECLARE @replace NVARCHAR(1000) = N'_';
SELECT REPLACE(CAST(@text AS VARCHAR), CAST(@find AS VARCHAR), CAST(@replace AS VARCHAR));
The þ character (Extended ASCII { via ISO-8859-1 and ANSI Code Page 1252 } & UNICODE value of 254) is known as "thorn" and in some languages equates directly to th:
Technical info on the character here: http://unicode-table.com/en/00FE/
Explanation of that character and collations here: http://userguide.icu-project.org/collation/customization. Search the page — typically Control-F
— for "Complex Tailoring Examples" and you will see the following:
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.
If you do not want þ to equate to th, then force a Binary collation as follows:
SELECT REPLACE(N'this is the news with a þ' COLLATE Latin1_General_100_BIN2,
N'þ', N'__');
Returns:
this is the news with a __
For more info on working with Collations, Unicode, encodings, etc, please visit: Collations Info