C #: How can I convert strings to byte arrays?

Cr
- in PlayStation
6

I have the following problem: I want to convert four strings into four byte [] arrays in C #. However, this does not seem to work as it should.

Here is my code:

string InputByteAr1 = textBox2.Text;
string InputByteAr2 = textBox3.Text;
string InputByteAr3 = textBox4.Text;
string InputByteAr4 = textBox5.Text;
byte [] bufferoutput1 = System.Text.Encoding.UTF8.GetBytes (InputByteAr1);
byte [] bufferoutput2 = System.Text.Encoding.UTF8.GetBytes (InputByteAr2);
byte [] bufferoutput3 = System.Text.Encoding.UTF8.GetBytes (InputByteAr3);
byte [] bufferoutput4 = System.Text.Encoding.UTF8.GetBytes (InputByteAr4);

PS3.SetMemory (Output, new byte [] {bufferoutput1, bufferoutput2, bufferoutput3, bufferoutput4});

Ok, now one wonders what the PS3.SetMemory should mean.

The program connects to the Playstation 3. I have four text boxes set to my Windows Form. The output next to the SetMemory is a Uint, which I could successfully convert from String to Uint.

Well, when I try to convert strings to byte [] arrays:

The type "byte []" can't be implicitly converted to "byte".

The type "byte []" can't be implicitly converted to "byte".

The type "byte []" can't be implicitly converted to "byte".

The type "byte []" can't be implicitly converted to "byte".

This error message refers to the bufferoutput variables.

Does anyone have a solution? πŸ˜•

Ki

Does anyone have a solution?

Yes.

You have four byte arrays and you want to put them in another byte array?

int [] arr = new int [] {1, 2, 3, 4};

This creates an int array, so each item must be an int.

Exactly the same applies to your byte array, what you want to pass to the SetMemory method:

byte [] arr = new byte [] {bufferoutput1, bufferoutput2, bufferoutput3, bufferoutput4};

This creates a byte array, so each item must be one byte.

Either you take byte [] [] or you use Concat:

byte [] arr = new byte [] [] {bufferoutput1, bufferoutput2, bufferoutput3, bufferoutput4};

byte [] arr = bufferoutput1.Concat (bufferoutput2) .ToArray ();

ma

At

new byte [] {bufferoutput1, bufferoutput2, bufferoutput3, bufferoutput4}

There must be a list of bytes within the brace and not a list of byte arrays. If you want to join several byte arrays, then… But that stands u.a. Already described here:

https://stackoverflow.com/...in-c-sharp

Cr

Thanks, now no error will be issued, but it says: The input string has the wrong format.

ma

Where? Which line?

Cr

If I enter something in the text box of Outputb (uint), this error comes. Then when I enter something in the bytebufferoutput textboxes, the same thing happens.

ma

I do not understand the formulations. What is "Textbox of Outputb (uint)"? Do you mean while typing?

I meant in which code line does the error occur? Where is the above code (in which event handler)?

Ark Bloodstalker on ps4? ka kamarisweatshirt
Ps4 broken? Se SerenaCedar