asp里如何把字符串赋给字节数组

时间:2023-01-11 20:38:27
dim s as string
dim buff() as byte
a="abcdefg"
buff=a

在vb6.0里是可以这样把字符串变量S赋给buff字节数组
在asp里代码怎么写呢,谢谢 

5 个解决方案

#1


字节数组中的每个元素对应字符串中的每个字符的内码值
asp 是用 mid 函数取得字符串指定位置的字符吧,是用 asc 函数取得字符的内码值吧?
那么写一个循环不就转换过去了吗?

#2


dim s
dim buff()
s="abcdefg"
buff=myStringToByte(s)

Function myStringToByte(s)

's是字符串变量string,值是s="abcdefg"
'字节数组是怎么声明呢
'如何用循环转换呢
'这个函数返回的是字节数组
'这个函数完整代码怎么写呢

end Function

#3


dim s
s="abcdefg"
buff=myStringToByte(s)
response.write buff(0)


Function myStringToByte(s)
  dim arr()
  dim l
  l=len(s)-1
  redim arr(l)
  for i=0 to l
    arr(i)=asc( mid(s,i+1,1))
  next

  myStringToByte=arr
end Function

#4


dim s
s="abcdefg"
buff=myStringToByte(s)
response.write buff(0)
 
 
Function myStringToByte(s)
  dim arr()
  dim l
  l=len(s)-1
  redim arr(l)
  for i=0 to l
    arr(i)=asc( mid(s,i+1,1))
  next
 
  myStringToByte=arr
end Function

#5


<%
‘ 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,
%>

#1


字节数组中的每个元素对应字符串中的每个字符的内码值
asp 是用 mid 函数取得字符串指定位置的字符吧,是用 asc 函数取得字符的内码值吧?
那么写一个循环不就转换过去了吗?

#2


dim s
dim buff()
s="abcdefg"
buff=myStringToByte(s)

Function myStringToByte(s)

's是字符串变量string,值是s="abcdefg"
'字节数组是怎么声明呢
'如何用循环转换呢
'这个函数返回的是字节数组
'这个函数完整代码怎么写呢

end Function

#3


dim s
s="abcdefg"
buff=myStringToByte(s)
response.write buff(0)


Function myStringToByte(s)
  dim arr()
  dim l
  l=len(s)-1
  redim arr(l)
  for i=0 to l
    arr(i)=asc( mid(s,i+1,1))
  next

  myStringToByte=arr
end Function

#4


dim s
s="abcdefg"
buff=myStringToByte(s)
response.write buff(0)
 
 
Function myStringToByte(s)
  dim arr()
  dim l
  l=len(s)-1
  redim arr(l)
  for i=0 to l
    arr(i)=asc( mid(s,i+1,1))
  next
 
  myStringToByte=arr
end Function

#5


<%
‘ 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,
%>