473,416 Members | 1,570 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

Convert string to a STRING Byte array

1
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
OR
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..
thanks

<edit by mod: use [code] tags, not [i] tags>
Nov 14 '08 #1
5 4806
debasisdas
8,127 Expert 4TB
question moved to .NET movie.
Nov 15 '08 #2
joedeene
583 512MB
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.

Example:

Expand|Select|Wrap|Line Numbers
  1.         byte[] mystringbytearray;
  2.         mystringbytearray = System.Text.Encoding.ASCII.GetBytes("gfhg");
  3.  
joedeene
Nov 15 '08 #3
balabaster
797 Expert 512MB
VB:
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)
C#
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
Plater
7,872 Expert 4TB
I think perhaps the op wants a "hex string" representation of their string.

For instance if one had:
"A BALL"
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
balabaster
797 Expert 512MB
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

1
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...
6
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...
15
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?
6
by: Allan Ebdrup | last post by:
How do I easily convert a int to a string? Kind Regards, Allan Ebdrup
6
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...
6
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...
12
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} ...
19
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...
0
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
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,...
0
jinu1996
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...
0
tracyyun
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...

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.