M
Markus Freitag
Guest
Hello,
How I can delete the BOM?
Picture 1 and 2
Thanks for tips.
Greetings Markus
private static string RemoveBom(string p)
{
string BOMMarkUtf8 = Encoding.UTF8.GetString(Encoding.UTF8.GetPreamble());
if (p.StartsWith(BOMMarkUtf8, StringComparison.OrdinalIgnoreCase))
p = p.Remove(0, BOMMarkUtf8.Length);
return p.Replace("\0", "");
}
private async void FileReadOrTimeout(object sender, RoutedEventArgs e)
{
try
{
var ret = await ReadDataAsync(@"C:\Users\Freitag\Documents\TEST_M_3.xml", 2000);
string converted = Encoding.UTF8.GetString(ret, 0, ret.Length);
converted = RemoveBom(converted);
MessageBox.Show(converted + "\n \nEnd");
}
}
private async Task<byte[]> ReadDataAsync(string pDatei, int pTimeOutMs)
{
int n = 0;
int m = (int)Math.Ceiling(pTimeOutMs / 100.0);
while (!File.Exists(pDatei))
{
await Task.Delay(100);
n++;
if (n == m)
throw new FileNotFoundException();
}
FileInfo fi = new FileInfo(pDatei);
Stream streamXML;
byte[] data = new byte[fi.Length];
using (var fs = fi.OpenRead())
{
int read = await fs.ReadAsync(data, 0, data.Length);
streamXML = new MemoryStream(data);
var gpx = Deserialize<Msg>(streamXML);
return data;
}
}
//######################################################
Continue reading...
How I can delete the BOM?
Picture 1 and 2
Thanks for tips.
Greetings Markus
private static string RemoveBom(string p)
{
string BOMMarkUtf8 = Encoding.UTF8.GetString(Encoding.UTF8.GetPreamble());
if (p.StartsWith(BOMMarkUtf8, StringComparison.OrdinalIgnoreCase))
p = p.Remove(0, BOMMarkUtf8.Length);
return p.Replace("\0", "");
}
private async void FileReadOrTimeout(object sender, RoutedEventArgs e)
{
try
{
var ret = await ReadDataAsync(@"C:\Users\Freitag\Documents\TEST_M_3.xml", 2000);
string converted = Encoding.UTF8.GetString(ret, 0, ret.Length);
converted = RemoveBom(converted);
MessageBox.Show(converted + "\n \nEnd");
}
}
private async Task<byte[]> ReadDataAsync(string pDatei, int pTimeOutMs)
{
int n = 0;
int m = (int)Math.Ceiling(pTimeOutMs / 100.0);
while (!File.Exists(pDatei))
{
await Task.Delay(100);
n++;
if (n == m)
throw new FileNotFoundException();
}
FileInfo fi = new FileInfo(pDatei);
Stream streamXML;
byte[] data = new byte[fi.Length];
using (var fs = fi.OpenRead())
{
int read = await fs.ReadAsync(data, 0, data.Length);
streamXML = new MemoryStream(data);
var gpx = Deserialize<Msg>(streamXML);
return data;
}
}
//######################################################
Continue reading...