UTF-8 strings in .NET


This issue has been fixed in version 2.1.0

To display the output properly from the Sat.MakePipeStringFromXml and Sat.GetXmlAttribute methods in .NET, use this fix.

In VB.NET,
Public Function FixUTF8StringForDisplay(ByVal s As String) As String
    Dim b As Byte() = System.Text.Encoding.GetEncoding(28591).GetBytes(s)
    Dim newstr As String = System.Text.Encoding.UTF8.GetString(b)
    Return newstr
End Function
For example,
Console.WriteLine(vbLf & "FORM THE PIPESTRING FROM AN XML FILE:")
fname = "Muestra_v2_signed2.xml"
s = Sat.MakePipeStringFromXml(fname)
Console.WriteLine("Sat.MakePipeStringFromXml('{0}')=" & vbLf & "{1}", fname, s)
Debug.Assert(s.Length > 0, "Sat.MakePipeStringFromXml failed")

' Display properly!
Console.WriteLine("FixUTF8StringForDisplay='{0}'", FixUTF8StringForDisplay(s))
In C#,
public static string FixUTF8StringForDisplay(string s)
{
    byte[] b = System.Text.Encoding.GetEncoding(28591).GetBytes(s);
    string newstr = System.Text.Encoding.UTF8.GetString(b);
    return newstr;
}
Console.WriteLine("\nFORM THE PIPESTRING FROM AN XML FILE:");
fname = "Muestra_v2_signed2.xml";
s = Sat.MakePipeStringFromXml(fname);
Console.WriteLine("Sat.MakePipeStringFromXml('{0}')=\n{1}", fname, s);
Debug.Assert(s.Length > 0, "Sat.MakePipeStringFromXml failed");

// Display properly!
Console.WriteLine("FixUTF8StringForDisplay='{0}'", FixUTF8StringForDisplay(s));

Yes, we know these are kludges. Better behaved methods will come in future updates. Fixed in version 2.1.0 (November 2010). Thanks to Benjamin for pointing out this issue.

Contact

For further information, please Email Us.

This page last updated 2 November 2010