Last active
October 10, 2023 20:57
-
-
Save multinerd/2c3107819c2e2cccda8a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Convert Base64 value in a variable to varbinary: | |
declare @str varchar(20); | |
set @str = '3qAAAA=='; | |
select cast(N'' as xml).value('xs:base64Binary(sql:variable("@str"))', 'varbinary(20)'); | |
-- Convert binary value in a variable to Base64: | |
declare @bin varbinary(20); | |
set @bin = 0xDEA00000; | |
select cast(N'' as xml).value('xs:base64Binary(xs:hexBinary(sql:variable("@bin")))', 'varchar(20)'); | |
-- Convert varbinary value in a column to Base64: | |
select top (10) cast(N'' as xml).value('xs:base64Binary(xs:hexBinary(sql:column("qs.sql_handle")))', 'varchar(512)') as sql_handle_base64 | |
into #t | |
from sys.dm_exec_query_stats as qs; | |
-- Convert Base64 value in a column to varbinary: | |
select cast(N'' as xml).value('xs:base64Binary(sql:column("t.sql_handle_base64"))', 'varbinary(20)') as sql_handle | |
from #t as t; | |
drop table #t; | |
NSString *plainString = @"foo"; | |
--Encode | |
NSData *plainData = [plainString dataUsingEncoding:NSUTF8StringEncoding]; | |
NSString *base64String = [plainData base64EncodedStringWithOptions:0]; | |
NSLog(@"%@", base64String); | |
--Decode | |
NSData *decodedData = [[NSData alloc] initWithBase64EncodedString:base64String options:0]; | |
NSString *decodedString = [[NSString alloc] initWithData:decodedData encoding:NSUTF8StringEncoding]; | |
NSLog(@"%@", decodedString); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment