473,666 Members | 2,039 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Byte arry to text for textbox

I want to convert a byte array to a string or text to write it out in a
multiline textbox. I've tried encoding, and converting but end up with
nothing in the textbox.

The strange thing is that it writes out fine to a text document using
StreamWriter.

So I have this tcp/ip app that receives everything into a byte array.
I then want to write out what it was that was passed to me, into a
multiline textbox.

Any ideas?

Thanks
Tom

May 10 '06 #1
9 11012
Tom,

The encoder is the right way to go. It is possible that you are using
it the wrong way.

Can you post the relevant sections of your code?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"tawright91 5" <ta*********@ya hoo.com> wrote in message
news:11******** **************@ j33g2000cwa.goo glegroups.com.. .
I want to convert a byte array to a string or text to write it out in a
multiline textbox. I've tried encoding, and converting but end up with
nothing in the textbox.

The strange thing is that it writes out fine to a text document using
StreamWriter.

So I have this tcp/ip app that receives everything into a byte array.
I then want to write out what it was that was passed to me, into a
multiline textbox.

Any ideas?

Thanks
Tom

May 10 '06 #2
Hello, tawright915!

t> The strange thing is that it writes out fine to a text document using
t> StreamWriter.

t> So I have this tcp/ip app that receives everything into a byte array.
t> I then want to write out what it was that was passed to me, into a
t> multiline textbox.

In text you can see your data in the hex format, if it is okay for you you can convert byte array to string
using "X" format in the ToString(...) method ( .ToString("X") )

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
May 10 '06 #3
Have you tried System.Text.ASC IIEncoding.GetS tring(System.By te[])?

smc750
www.certdev.com

tawright915 wrote:
I want to convert a byte array to a string or text to write it out in a
multiline textbox. I've tried encoding, and converting but end up with
nothing in the textbox.

The strange thing is that it writes out fine to a text document using
StreamWriter .

So I have this tcp/ip app that receives everything into a byte array.
I then want to write out what it was that was passed to me, into a
multiline textbox.

Any ideas?

Thanks
Tom


--
smc750
www.certdev.com

Message posted via DotNetMonster.c om
http://www.dotnetmonster.com/Uwe/For...sharp/200605/1
May 10 '06 #4
Yeah, my code is:
textBox1.Text = Encoding.UTF8.G etString(e.Recv dBuffer, 0,
e.RecvdBufferSi ze);
Thanks
Tom

May 11 '06 #5
tawright915 <ta*********@ya hoo.com> wrote:
Yeah, my code is:
textBox1.Text = Encoding.UTF8.G etString(e.Recv dBuffer, 0,
e.RecvdBufferSi ze);


And does the buffer genuinely represent UTF-8 encoded text? If it
doesn't, the above is likely to produce gibberish.

Where did the byte array come from, and how do you actually want to
display it?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
May 11 '06 #6
What does the value of e.RecvdBufferSi ze show? What type is e?

May 11 '06 #7
The buffer is the receive buffer from my socket connection.
The complete code is this:

private void msh_OnMessageRc vd(object sender, ReceivedData e)
{
listBox1.Items. Add("Data Received");

char[] hexDigits = {'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
byte[] bytes = new byte[e.RecvdBufferSi ze];
bytes = e.RecvdBuffer;
char[] chars = new char[bytes.Length * 2];
for (int i = 0; i < bytes.Length; i++)
{
int b = bytes[i];
chars[i * 2] = hexDigits[b >> 4];
chars[i * 2 + 1] = hexDigits[b & 0xF];
}
StreamWriter sr = File.CreateText ("c:\\myNYSPINd ump.txt");
sr.Write(Encodi ng.UTF8.GetStri ng(e.RecvdBuffe r, 0,
e.RecvdBufferSi ze));
sr.Close();
listBox1.Items. Add(new string(chars));
textBox1.Text = Encoding.UTF8.G etString(e.Recv dBuffer, 0,
e.RecvdBufferSi ze);
//listBox1.Items. Add("Raw Message: " +
Encoding.ASCII. GetString(e.Rec vdBuffer, 26, e.RecvdBufferSi ze - 4));
}
Basically I'm converting the buffer first to a char to put into a
listbox (Which I plan on removing). Then I write it to a text file.
(this too is going I just had this here to see what was coming in)
Then I'm trying to write it out to a multiline textbox.

May 11 '06 #8
Good question...I need to check. However it should show the correct
size as the list box and the streamwriter is writing out the correct
string.

May 11 '06 #9
tawright915 <ta*********@ya hoo.com> wrote:
The buffer is the receive buffer from my socket connection.
The complete code is this:


<snip>

Well, that doesn't really tell us what the content of the data is. If
it's arbitrary binary data (which it looks like you're expecting it to
be, given that you're writing it to a text file as hex) why not just
display it as hex too?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
May 12 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2529
by: kuhni | last post by:
Hi everybody! After searching newsgroups for a couple of hours, I now try asking directly (running the risk of asking again the same question). My problem is to predict when the size of the database (1GB I expect) is over 1GB by calculating the maximal number of data sets (tuple) added: 1. Is the following calculation for estimating the mdb file size in Access 97 correct: 1 integer field = 4 Byte
0
1215
by: Earl Teigrob | last post by:
I can create a new custom control (and not change it) and add it to the toolbox and drag it onto the disign screen and it works just fine, displaying the text . However, when I add the following datepicker control to the toolbox, it just shows a yellow dot and thats it. What happened to the text??? Earl
1
2064
by: John Dalberg | last post by:
I have a datagrid plus a button to save the contents of the grid to the database. My code gets blanks in the textbox field. I am not sure why. Also I don't know why dgi.Cells.Controls & dgi.Cells.Controls are Literal Controls. The html shows only a textbox in the second table cell. This is the code and below is the grid. Code: private void btnSave_Click(object sender, System.EventArgs e)
12
7761
by: Mark Rae | last post by:
Hi, Can anyone please tell me how to convert an unserializeable object say, a System.Web.Mail.MailMessage object, to a byte array and then convert the byte array to a Base64 string? Any assistance gratefully received. Best regards,
1
9769
by: Emilio | last post by:
Question about Dim data As () = System.Text.Encoding.ASCII.GetBytes(message) Would it be the same to write: Dim data() As Byte = System.Text.Encoding.ASCII.GetBytes(message) ?
4
5464
by: Neil | last post by:
Just found out that the Microsoft Rich Textbox does not support full text justification, since it's based on Version 1.0 of the RichEdit Window Class, and full text justification is only available in versions 3.0 or later of the class. However, also just found out that the new Rich Text property in Access 2007 ALSO does not support full text justification! This seems incredible, that MS would create a brand new application, and not...
2
2172
by: krishnasamy | last post by:
Hi, I have invoking the "NewDll.Dll" which created using vc++. In this Dll a method return the array data following way, BYTE NewDemoDll::RetLiveImg() { return bufferData; } How can I write the code in Java to get the data from the above method?
1
7006
by: daonho | last post by:
I tried to use javascript to trigger up the button click function when user press enter key from the textbox. This function work fine with a single button click such has login page. However, if the page has multiple button such login page with a search function somewhere around, then it's not respond properly. I have attached a brief example of two text boxes and two button. When ever a key is press on textbox one, I want to trigger...
5
2351
by: =?Utf-8?B?RmFtaWx5IFRyZWUgTWlrZQ==?= | last post by:
I'm sorry, but I've read your code a couple of times and just don't see where the Form1 is initialized. Form1 also sounds like a class name, and this would be how you could do some form operations in vb6, but not in .Net. This would explain why the messagebox works, as it is not instantiated, but called statically as you did in your code. I think you need this where your MsgBox is called: dim ui as New Form1() ui.txt_rec.Text =...
0
8869
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, 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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8551
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8639
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 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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7386
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6198
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5664
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4198
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1775
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.