I'm trying to convert VTK (vtu) XML-format files from base64 binary strings to ASCII strings. The files look a bit like this:
<Points>
<DataArray type="Float32" NumberOfComponents="3" format="binary">
`gJQGAGp7+sJTMbPCVWiWv4RP+8LbKrTCj0yDv1kC+8J5w7PCUe0xv34YAMNqprTCtsRDv7yw/8IgdLTCUE0lv/8 (etc...)
</DataArray>
</Points>
You can also have these files in ASCII format, so in ASCII the same thing looks like:
<Points>
<DataArray type="Float32" Name="Points" NumberOfComponents="3" format="ascii" RangeMin="9.6120050431" RangeMax="280.36424584">
-125.24104309 -89.596336365 -1.1750589609 -125.65530396 -90.083702087 -1.0257738829
-125.50458527 -89.881782532 -0.69502741098 -128.09567261 -90.325027466 -0.7647203207
-127.84518433 -90.226806641 -0.64571094513 -128.24607849 -90.475311279 -0.61999017
(etc...)
</DataArray>
</Points>
I need my code to work for when the files come in ASCII or binary, so I need to be able to convert the base64 string in the first case to the ASCII format in the second case.
Right now I have:
string pointString = nodeList[0].ChildNodes.Item(0).InnerText.Trim();
if(format.Equals("binary", StringComparison.InvariantCultureIgnoreCase))
{
byte[] bytes = Convert.FromBase64String(pointString);
pointString = Encoding.ASCII.GetString(bytes);
}
aaand my string is coming out all wrong:
pointString: ?$
I feel like I'm missing something simple here. Where am I going wrong?