开发者

Convert a string array to byte array

开发者 https://www.devze.com 2022-12-27 11:24 出处:网络
I want to make a file which reads String array but initially I am having only byte array so first I want to convert i开发者_开发问答t into string array, so how can I do so. Try this:

I want to make a file which reads String array but initially I am having only byte array so first I want to convert i开发者_开发问答t into string array, so how can I do so.


Try this:

Byte[] bytes = System.Text.Encoding.UTF8.GetBytes(yourString);

You may need to change this up depending on the character encoding of your string - please see System.Text.Encoding (specifically its properties) for other encodings that are supported by this type.

If you need to go the other way (and convert a Byte[] to a String) then do this (The advice on character encoding still applies here as well):

String yourString = System.Text.Encoding.UTF8.GetString(yourByteArray);

It sounds like your the API you are using expects a String[] and a call to GetString will provide you with just a single instance of String, not an array. Perhaps something like this will work for your API call:

String yourString = System.Text.Encoding.UTF8.GetString(yourByteArray);
someType.ApiCall(new[] { yourString });
0

精彩评论

暂无评论...
验证码 换一张
取 消