Solved

Convert string to byte array

Posted on 2004-08-25
14
217 Views
Last Modified: 2010-08-05
title says it all

also, if you are aware, can someone post how i would insert a byte array into a database using oracleclient
0
Comment
Question by:lmpsteelwire
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
14 Comments
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 11893436
get string from byte array ...
Dim myArray As Byte() = {50, 70, 71}
Dim s2 As String
s2 = System.Text.Encoding.ASCII.GetString(myArray)

GetBytes() will return a byte array for a string
Dim myArray As Byte()
Dim s2 As String = "hello"
myArray = System.Text.Encoding.ASCII.GetBytes(s2)


http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemtextencodingclassasciitopic.asp

depending on your data you may want to use the UTF encoding object ... the help explains why you may want to do this.
0
 
LVL 37

Accepted Solution

by:
gregoryyoung earned 250 total points
ID: 11893458
0
 
LVL 14

Expert Comment

by:ptakja
ID: 11893522
Dim bytValue As Byte()
bytValue = Convert.FromBase64String(strYourString)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 37

Expert Comment

by:gregoryyoung
ID: 11893583
that will only work if you base64 encode the data on the way in ...
0
 
LVL 2

Author Comment

by:lmpsteelwire
ID: 11893593
ya, its a BLOB, which is just a paragraph of text
0
 
LVL 4

Expert Comment

by:Daniellus83
ID: 11893703
I am just gonna you the answer to the 'title'-question:

Code to convert a string into a byte array:

    Dim YourString as String
    Dim ByteArray(1) As Byte  'Just give it a dimension

    Sub CopyIntoByteArray()

        Dim i, intArraySize  As Integer
       
        intArraySize = CInt((Len(YourString) + 1) / 2) - 1
        ReDim ByteArray(intArraySize)

        For i = 0 To intArraySize
            ByteArray(i) = "&H" & Mid(YourString , i * 2 + 1, 2)
        Next i

    End Sub

...this should do the trick...

Try it and maybe you like it!
0
 
LVL 2

Author Comment

by:lmpsteelwire
ID: 11893724
hmm...ok i made my oraclelob object, and used .write...but how do i set it up to go a row, right column, of right table...i think somewhere i got lost here.
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 11893755
there is an example on the link.
0
 
LVL 2

Author Comment

by:lmpsteelwire
ID: 11893804
duh. sorry, it was a long night. thanks greg
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 11893863
coffee or beer ? :)

Glad to help.

Cheers,

Greg
0
 
LVL 2

Author Comment

by:lmpsteelwire
ID: 11893957
keg between about 5 of us

sure is great to be back to work on a wednesday morning.
0
 
LVL 2

Author Comment

by:lmpsteelwire
ID: 11896482
in the c# example, they use: CreateTempLob(cmd, BLOB.LobType)

and i definitely cant use that in vb.net...do you know the equivilant?
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 11896970
actually I think thats just a little function they wrote and forgot to copy into the example that would just instantiate a lob object with the command object and blobtype.
0
 
LVL 2

Author Comment

by:lmpsteelwire
ID: 11897156
excellent
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question