Solved

Convert string to byte array

Posted on 2004-08-25
14
210 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
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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

895 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now