7

I want to make a file which reads String array but initially I am having only byte array so first I want to convert it into string array, so how can I do so.

1
  • 1
    Use StreamReader to read strings from a file. File.ReadAllLines() is the quick way. Commented Apr 17, 2010 at 16:54

1 Answer 1

17

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 });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.