Technical Article

convert string to ascii values

,

Load a string into the @x variable, then execute the script. This is handy for finding HTML characters.

/*
Convert string to ascii values
Loop each character and print it's ascii value
*/
declare @x nvarchar(100), @i int, @k int,@v int

--load this variable
set @x = 'AZ az' + char(160) + '01' -- note: 160 is an html non breaking space

print @x
print '----------------'
print '' + char(9) + 'int' + char(9) + 'hex'
set @i = 0
while @i < LEN(@x)
begin
  set @i = @i +1
  set @v = ascii(substring(@x,@i,1))
  print substring(@x,@i,1) + char(9) + convert(varchar,@v) + char(9) + convert(varchar,CONVERT(varbinary,@v),2)
end

Rate

2.75 (4)

You rated this post out of 5. Change rating

Share

Share

Rate

2.75 (4)

You rated this post out of 5. Change rating