EDN Admin
Well-known member
Hi Forum this problem has been bothering me for some time and I have yet to find a simple solution. My code parses txt files to data objects containing strings that eventually gets serialize to XML. Since the source files contain characters which
must be converted to escape sequences within XML the plan is to always do this ahead of time. The simple .NET C# function Ive written is below...
private string ReplaceDegreeChars(string s)<br/>
{<br/>
const string repstr = "°";<br/>
//const char degree = (char)176;<br/>
<br/>
string degreestr = "°";<br/>
//string degreestr = degree.ToString();<br/>
string newstr = s.Replace(degreestr, repstr);<br/>
<br/>
return newstr;<br/>
}<br/>
As you suspect the code in any form above fails miserably. Does anyone know why? Im assuming that the TextReader Im using and the Split method is handling unicode as expected. But even s.Contains(degree) on the parameter above never returns
true.
A copy paste from a single line in my test file is below. I use Split with a comma delimeter and then trim of the quotations, and then call ReplaceDegreeChars for each item on the line.
"EVNT","0F000002","APU Oil Temp High - Oil Temp >135°C",1
Thanks for any hints as to why this code is very very bad (other than its performance of course).
Wil
View the full article
must be converted to escape sequences within XML the plan is to always do this ahead of time. The simple .NET C# function Ive written is below...
private string ReplaceDegreeChars(string s)<br/>
{<br/>
const string repstr = "°";<br/>
//const char degree = (char)176;<br/>
<br/>
string degreestr = "°";<br/>
//string degreestr = degree.ToString();<br/>
string newstr = s.Replace(degreestr, repstr);<br/>
<br/>
return newstr;<br/>
}<br/>
As you suspect the code in any form above fails miserably. Does anyone know why? Im assuming that the TextReader Im using and the Split method is handling unicode as expected. But even s.Contains(degree) on the parameter above never returns
true.
A copy paste from a single line in my test file is below. I use Split with a comma delimeter and then trim of the quotations, and then call ReplaceDegreeChars for each item on the line.
"EVNT","0F000002","APU Oil Temp High - Oil Temp >135°C",1
Thanks for any hints as to why this code is very very bad (other than its performance of course).
Wil
View the full article