I need to convert a string array to a byte array. I know this question has been posted and answered many times, but for some reason, none of the solutions work for me.
Here is the most common solution:
public static byte[] StringArrayToByteArray(string[] someStringArray)
{
return someStringArray.Select(s => Convert.ToByte(s, 16)).ToArray();
}
However, when I run this, I get the following errors: FormatException: Could not find any parsable digits.
or FormatException: Additional unparsable characters are at the end of the string.
I need to save letters, along with a separator (/), for my data. Here is my code:
string[] stringArray = new string[map.Size.x * map.Size.y];
int counter = 0;
for (int y = (int) map.Rect.y; y < map.Rect.yMax; y++)
{
for (int x = (int) map.Rect.x; x < map.Rect.xMax; x++)
{
stringArray[counter] = map[x,y].Name;
stringArray[counter] += "/";
counter++;
}
}
Then I need to convert this string[] to a byte array.