Hello all.

I have a string, e.g. "Testing" and I try to convert it to byte but I get a NumberFormatException. I tried with (byte), Byte.Parsebyte.


Any help?

thanks

Recommended Answers

All 7 Replies

Your string can only contain digits or start with a "-" otherwise a NumberFormatException is bound to be thrown...

so if it start with - and be "-Testing" is it ok?

Oh no, sorry you understood me wrong. The string must only have numbers the "-" that I used meant that it can be "minus" number as in "-134" for example. You can't have any letters in that string.

What are you trying to do? Ahy do you want to convert the String to a byte?

I am sending data from a server to a client using UDP. I am getting the data from a database. The first string is the user's name and I am trying to send it to the client for showing it on the homepage. Something like: Welcome <name>.

For sending it using UDP I have to change it to byte.

I wish I could help you there man, I know nothing of UDP at all. I do know however(as far as my knowledge goes) that you cannot convert a string to a byte.. Sorry bro

You did help. You made me realize that I have to find another way of doing it. I searched the net for it and found nothing.

So, when I saw this article I found the solution. I saw it before but I didn't think of it. The problem is that I have many strings. I have to make a byte array for sending the data. So, what I did is to merge all the strings with concat function and then send the byte array. Ta-da!! It worked!

Thanks Dean_Grobler! I really appreciate your help :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.