(SQL Server) HTML Entity Encode and Decode in StringBuilder
Demonstrates HTML encoding and decoding the contents of a StringBuilder. Note: This example requires Chilkat v11.1.0 or greater.
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
-- Important: Do not use nvarchar(max). See the warning about using nvarchar(max).
DECLARE @sTmp0 nvarchar(4000)
DECLARE @sb int
EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sb OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
DECLARE @s nvarchar(4000)
SELECT @s = '< é ü ç Ω Hello & World ✓ >'
DECLARE @success int
EXEC sp_OAMethod @sb, 'Append', @success OUT, @s
EXEC sp_OAMethod @sb, 'Encode', @success OUT, 'html', 'utf-8'
EXEC sp_OAMethod @sb, 'GetAsString', @sTmp0 OUT
PRINT @sTmp0
-- Output:
-- < é ü ç Ω Hello & World ✓ >
-- To decode:
EXEC sp_OAMethod @sb, 'Decode', @success OUT, 'html', 'utf-8'
EXEC sp_OAMethod @sb, 'GetAsString', @sTmp0 OUT
PRINT @sTmp0
-- Output:
-- < é ü ç Ω Hello & World ✓ >
EXEC @hr = sp_OADestroy @sb
END
GO
|