'programming'에 해당되는 글 387건

  1. 2012.08.31 ASP Byte Array Examples

반응형


http://www.example-code.com/asp/bytearray.asp

ASP Byte Array Examples

-------------------------------------------------------------------------------
Create Byte Array with Initialized Data
Create a byte array variable in ASP and initialize it with specific values.

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%

'
' Create a new byte array and initialize it with 4 bytes
' Byte values can be specified in hex or decimal.

Dim byteArray
byteArray = byteArray & ChrB(&H01)
byteArray = byteArray & ChrB(&HAA)
byteArray = byteArray & ChrB(3)
byteArray = byteArray & ChrB(4)


' Create a 16-byte array and initialize it with 0, 1, 2, 3, ...
Dim binaryKey
For i = 0 To 15
binaryKey = binaryKey & ChrB(i)
Next

%>
</body>
</html>

 

-------------------------------------------------------------------------------


Print Byte Array as Decimal Integers
Prints the byte values in a byte array as decimal integers.

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%

'
Dim key
For i = 0 To 15
key = key & ChrB(i)
Next


' Display the bytes as decimal integers:
Dim s
s = ""
For i = 1 To LenB(key)
    s = s & CStr(AscB(MidB(key, i, 1))) & ","
Next
Response.Write "<p>" & s & "</p>"

'Output: 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,

%>
</body>
</html>


-------------------------------------------------------------------------------


Byte Array Length
Use LenB to get the size of a byte array in ASP.

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%

'
' Create a byte array with 16 bytes:
Dim x
For i = 0 To 15
x = x & ChrB(i)
Next

' Displays 16
Response.Write LenB(x)

' If using LenB in a string expression, convert it to a string with CStr:
Response.Write "<p>" & CStr(LenB(x)) & "<p>"

%>
</body>
</html>

 

-------------------------------------------------------------------------------

 

Convert String to Byte Array Function
ASP function to convert a string to a byte array.

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%

'
' String to byte array conversion function:
Function StringToByteArray(s)
  Dim i, byteArray
  For i=1 To Len(s)
    byteArray = byteArray & ChrB(Asc(Mid(s,i,1)))
  Next
  StringToByteArray = byteArray
End Function

s = "ABCDEFG"

' Convert the string to a byte array.
Dim byteArray
byteArray = StringToByteArray(s)

' Display the length of the byte array
Response.Write CStr(LenB(byteArray)) & "<p>"

' Display the bytes as decimal integers:
Dim d
d = ""
For i = 1 To LenB(byteArray)
    d = d & CStr(AscB(MidB(byteArray, i, 1))) & ","
Next
Response.Write "<p>" & d & "</p>"

' Output: 65,66,67,68,69,70,71,

%>
</body>
</html>


-------------------------------------------------------------------------------


Convert Byte Array to String Function
ASP function to convert a byte array to string.

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%

'
' Byte array to string conversion function:
Function ByteArrayToString(x)
  Dim i, s
  For i = 1 To LenB(x)
    s = s & Chr(AscB(MidB(x, i, 1)))
  Next
  ByteArrayToString = s
End Function

' Create a byte array with the us-ascii values for "ABCDEFG"
' 65,66,67,68,69,70,71
Dim a
a = a & ChrB(65)
a = a & ChrB(66)
a = a & ChrB(67)
a = a & ChrB(68)
a = a & ChrB(69)
a = a & ChrB(70)
a = a & ChrB(71)

' Convert the byte array to a string:
Dim s
s = ByteArrayToString(a)

' Display the string:
Response.Write s

%>
</body>
</html>

 


 

반응형
Posted by 공간사랑
,