Solved

Convert string to byte array

Posted on 2004-08-25
14
209 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 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

12 Experts available now in Live!

Get 1:1 Help Now