| |

VerySource

 Forgot password?
 Register
Search
View: 723|Reply: 3

〓〓〓〓 Anxious! !! How to assign values ​​to some array of a byte array?

[Copy link]

1

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-14 18:00:01
| Show all posts |Read mode
Define a byte array byte [1024] a

Want a [0] to a [10] to be a string and a [11] to start with other data

How to assign a string to a [0] -a [11]? String length is 11
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-18 22:27:01
| Show all posts
Try to use your string as a char array and use a for loop to convert them one by one into a byte [1024] a
Reply

Use magic Report

0

Threads

56

Posts

21.00

Credits

Newbie

Rank: 1

Credits
21.00

 China

Post time: 2020-1-19 15:27:02
| Show all posts
Is the way upstairs
            byte [] a = new byte [1024];
            string str = "sssssssssssss";
            char [] arr = str.ToCharArray ();
            for (int i = 0; i <str.Length; i ++)
            {
                a [i] = (byte) arr [i];
            }

"byte [1024] a" It seems wrong to define a byte array like this ...
Reply

Use magic Report

0

Threads

56

Posts

21.00

Credits

Newbie

Rank: 1

Credits
21.00

 China

Post time: 2020-1-19 17:00:01
| Show all posts
Forgot to convert to char []
for (int i = 0; i <str.Length; i ++)
{
    a [i] = (byte) str [i];
}
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list