473,567 Members | 2,902 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Convert string to a STRING Byte array

1 New Member
Hi experts,

I need to convert a string or a Byte array to a string byte array.

Its relatively easy to convert a string to an char array or a byte array but not a
Expand|Select|Wrap|Line Numbers
  1. STRING byte array. i.e. 
  2.             Dim Array() As Char
  3.             Dim strwork As String = "76A3kj9d6"
  4.             Array = strwork.ToCharArray
Expand|Select|Wrap|Line Numbers
  1.     Dim s As String = "76A3kj9d6"
  2.         MessageBox.Show("Base String:  " & s)
  3.         Dim b() As Byte = System.Text.UTF8Encoding.UTF8.GetBytes(s)
  4.         MessageBox.Show("Converted from byte array to string:  " & System.Text.UTF8Encoding.UTF8.GetString(b))
Please help..

<edit by mod: use [code] tags, not [i] tags>
Nov 14 '08 #1
5 4835
8,127 Recognized Expert Expert
question moved to .NET movie.
Nov 15 '08 #2
583 Contributor
I've never heard of a "string byte array". You can, however, get the bytes of a string and then place them in a byte array.


Expand|Select|Wrap|Line Numbers
  1.         byte[] mystringbytearray;
  2.         mystringbytearray = System.Text.Encoding.ASCII.GetBytes("gfhg");
Nov 15 '08 #3
797 Recognized Expert Contributor
Expand|Select|Wrap|Line Numbers
  1. Dim Converter As Encoding = Encoding.ASCII
  2. Dim InputString As String = "Hello World"
  3. Dim ByteResult() As Byte = Encoding.ASCII.GetBytes(InputString)
  4. Dim StringResult As String = Converter.GetString(ByteResult)
  5. Console.WriteLine(StringResult)
Expand|Select|Wrap|Line Numbers
  1. Encoding Converter = Encoding.ASCII;
  2. string InputString = "Hello World";
  3. byte[] ByteResult = Encoding.ASCII.GetBytes(InputString);
  4. string StringResult = Converter.GetString(ByteResult);
  5. Console.WriteLine(StringResult);
Nov 17 '08 #4
7,872 Recognized Expert Expert
I think perhaps the op wants a "hex string" representation of their string.

For instance if one had:
You would then have a hex string of:
"41 20 42 41 4C 4C"

This can be achieved by typecasting a byte or a char to an integer and then using the .ToString() overload to print out 2digit hex values
Nov 17 '08 #5
797 Recognized Expert Contributor
That'll teach me to answer posts when I'm falling asleep :oP
Nov 17 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Swarup | last post by:
I am reading a file (txt, xml, gif, ico, bmp etc) byte by byte and filling it into a byte arry. Now i have to convert it into a string to store it in the database. I use System.Text.UnicodeEncoding enc = new System.Text.UnicodeEncoding(); now i am using enc.GetString(value) and the value retured is one byte less if the size of the byte...
by: Ricardo Quintanilla | last post by:
i have a code that sends data to a socket listening over as400 platform, the socket responds to me as a "byte array". then i need to convert the "byte array" into a string. the problem is that the data converted from the byte array into a string , is not what i expect. example: - the data returned from the socket is (byte array)...
by: Kueishiong Tu | last post by:
How do I convert a Byte array (unsigned char managed) to a char array(unmanaged) with wide character taken into account?
by: Allan Ebdrup | last post by:
How do I easily convert a int to a string? Kind Regards, Allan Ebdrup
by: moondaddy | last post by:
I'm writing an app in vb.net 1.1 and need to convert a byte array into a string, and then from a string back to a byte array. for example Private mByte() as New Byte(4){11,22,33,44} Now how do I convert it to: dim myStr as string = "11,22,33,44"
by: Bob Altman | last post by:
Hi all, I'm looking for the fastest way to convert an array of bytes to String. I also need to convert a String back to its original Byte() representation. Convert.ToBase64String and Convert.FromBase64String seem like the closest thing I can find to what I'm looking for baked into the base class library. Can anyone suggest a better way...
by: Peter | last post by:
Trying to convert string to byte array. the following code returns byte array of {107, 62, 194, 139, 64} how can I convert this string to a byte array of {107, 62, 139, 65} System.Text.UTF8Encoding str = new System.Text.UTF8Encoding(); string s = new string((char)107, 1); s += new string((char)62, 1);
by: est | last post by:
From python manual str( ) Return a string containing a nicely printable representation of an object. For strings, this returns the string itself. The difference with repr(object) is that str(object) does not always attempt to return a string that is acceptable to eval(); its goal is to return a printable string. If no argument is given,...
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information inside an image, hide your complete image as text ,search for a particular image inside a directory, minimize the size of the image. However this is not...
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.