Solved

Convert string to byte array

Posted on 2004-08-25
14
215 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
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!

 
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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to open form using item in Listbox. 8 28
Expression Evaluater 3 45
RLDC Reporting in Visual studio 11 42
Vb.net progressbar with timer1 in visual studio win app 11 34
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

713 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