91 lines
3.8 KiB
HTML
91 lines
3.8 KiB
HTML
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!DOCTYPE html
|
|
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html lang="en-us" xml:lang="en-us">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
<meta name="security" content="public" />
|
|
<meta name="Robots" content="index,follow" />
|
|
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
|
|
<meta name="DC.Type" content="reference" />
|
|
<meta name="DC.Title" content="Convert strings and arrays of byte" />
|
|
<meta name="abstract" content="The following Visual Basic functions can assist in converting strings and arrays of byte." />
|
|
<meta name="description" content="The following Visual Basic functions can assist in converting strings and arrays of byte." />
|
|
<meta name="DC.Relation" scheme="URI" content="rzaikexecuteprepstmt.htm" />
|
|
<meta name="copyright" content="(C) Copyright IBM Corporation 1999, 2006" />
|
|
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 1999, 2006" />
|
|
<meta name="DC.Format" content="XHTML" />
|
|
<meta name="DC.Identifier" content="string2byte" />
|
|
<meta name="DC.Language" content="en-us" />
|
|
<!-- All rights reserved. Licensed Materials Property of IBM -->
|
|
<!-- US Government Users Restricted Rights -->
|
|
<!-- Use, duplication or disclosure restricted by -->
|
|
<!-- GSA ADP Schedule Contract with IBM Corp. -->
|
|
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
|
|
<link rel="stylesheet" type="text/css" href="./ic.css" />
|
|
<title>Convert strings and arrays of byte</title>
|
|
</head>
|
|
<body id="string2byte"><a name="string2byte"><!-- --></a>
|
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
|
<h1 class="topictitle1">Convert strings and arrays of byte</h1>
|
|
<div><p>The following Visual Basic functions can assist in converting strings
|
|
and arrays of byte.</p>
|
|
<div class="section"><pre>Public Sub Byte2String(InByte() As Byte, OutString As String)
|
|
'Convert array of byte to string
|
|
OutString = StrConv(InByte(), vbUnicode)
|
|
End Sub
|
|
|
|
Public Function String2Byte(InString As String, OutByte() As Byte) As Boolean
|
|
'vb byte-array / string coercion assumes Unicode string
|
|
'so must convert String to Byte one character at a time
|
|
'or by direct memory access
|
|
|
|
Dim I As Integer
|
|
Dim SizeOutByte As Integer
|
|
Dim SizeInString As Integer
|
|
|
|
SizeOutByte = UBound(OutByte)
|
|
SizeInString = Len(InString)
|
|
'Verify sizes if desired
|
|
|
|
'Convert the string
|
|
For I = 0 To SizeInString - 1
|
|
OutByte(I) = AscB(Mid(InString, I + 1, 1))
|
|
Next I
|
|
'If size byte array > len of string pad with Nulls for szString
|
|
If SizeOutByte > SizeInString Then 'Pad with Nulls
|
|
For I = SizeInString To SizeOutByte - 1
|
|
OutByte(I) = 0
|
|
Next I
|
|
End If
|
|
|
|
String2Byte = True
|
|
End Function
|
|
|
|
Public Sub ViewByteArray(Data() As Byte, Title As String)
|
|
'Display message box showing hex values of byte array
|
|
|
|
Dim S As String
|
|
Dim I As Integer
|
|
On Error GoTo VBANext
|
|
|
|
S = "Length: " & Str(UBound(Data)) & " Data (in hex):"
|
|
For I = 0 To UBound(Data) - 1
|
|
If (I Mod 8) = 0 Then
|
|
S = S & " " 'add extra space every 8th byte
|
|
End If
|
|
S = S & Hex(Data(I)) & " "
|
|
VBANext:
|
|
Next I
|
|
MsgBox S, , Title
|
|
|
|
End Sub</pre>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="rzaikexecuteprepstmt.htm" title="If an SQL statement is used more than once, it is best to have the statement prepared and then executed.">Execute prepared statements</a></div>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html> |