Convert string to byte array

title says it all

also, if you are aware, can someone post how i would insert a byte array into a database using oracleclient
LVL 2
lmpsteelwireIT / Business AnalystAsked:
Who is Participating?
 
gregoryyoungCommented:
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
 
ptakjaCommented:
Dim bytValue As Byte()
bytValue = Convert.FromBase64String(strYourString)
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
gregoryyoungCommented:
that will only work if you base64 encode the data on the way in ...
0
 
lmpsteelwireIT / Business AnalystAuthor Commented:
ya, its a BLOB, which is just a paragraph of text
0
 
Daniellus83Commented:
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
 
lmpsteelwireIT / Business AnalystAuthor Commented:
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
 
gregoryyoungCommented:
there is an example on the link.
0
 
lmpsteelwireIT / Business AnalystAuthor Commented:
duh. sorry, it was a long night. thanks greg
0
 
gregoryyoungCommented:
coffee or beer ? :)

Glad to help.

Cheers,

Greg
0
 
lmpsteelwireIT / Business AnalystAuthor Commented:
keg between about 5 of us

sure is great to be back to work on a wednesday morning.
0
 
lmpsteelwireIT / Business AnalystAuthor Commented:
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
 
gregoryyoungCommented:
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
 
lmpsteelwireIT / Business AnalystAuthor Commented:
excellent
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.