I have the following code:
StringBuilder data = new StringBuilder(); for (int i = 0; i < bytes1; i++) { data.Append("a"); } byte[] buffer = Encoding.ASCII.GetBytes(data);
But I get this error:
cannot convert from 'System.Text.StringBuilder' to 'char[]' The best overloaded method match for 'System.Text.Encoding.GetBytes(char[])' has some invalid arguments
StringBuilder data = new StringBuilder(); for (int i = 0; i < bytes1; i++) { data. Append("a"); } byte[] buffer = Encoding. ASCII. GetBytes(data.
Given a Byte value in Java, the task is to convert this byte value to string type. One method is to create a string variable and then append the byte value to the string variable with the help of + operator. This will directly convert the byte value to a string and add it in the string variable.
The following code will fix your issue.
StringBuilder data = new StringBuilder(); for (int i = 0; i < bytes1; i++) { data.Append("a"); } byte[] buffer = Encoding.ASCII.GetBytes(data.ToString());
The problem is that you are passing a StringBuilder
to the GetBytes
function when you need to passing the string result from the StringBuilder
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With