Want to create a string with given hexadecimal code values
I want to replace certain characters in the input string with other characters.
The input text contains left and right Microsoft smart quotes which I would like to convert to one ".
I was planning on using the Replace operation, but I'm having a hard time creating a text string to search.
I would like to replace the input sequence (hexadecimal) \ xE2809C and change this sequence to only one ". Same with \ xE2809D.
How do I create a string for use in a Replace operation?
I am thinking of something like (in a loop):
tempTxt = tempTxt.Replace(charsToRemove[i], charsToSubstitute[i]);
but I am unable to create the charsToRemove array.
Maybe the question is big: can the entire input file be read and converted to plain ASCII using some read / write and string conversions in C #.
Thanks Mike
source to share
I am using ReqPro40.dll to read data. The data is stored as text. I hope I haven't lost too much for copy / paste below. Below is everything I know. But I want to get rid of the longer sequences of bad characters. E2809C should be a quote, but I'm having trouble with that.
string tempTxt = Req.get_Tag(ReqPro40.enumTagFormat.eTagFormat_ReqNameOrReqText);
tempTxt=tempTxt.Substring(1, tempTxt.Length-1);
char[] charsToRemoveForXMLLegality = new char[]
{ '\x000a', '\x000b', '\x0002', '\x001e', // NL, VT, STX, RS
'\x0034', '\x8220', '\x8221', // ", left double, right double quote
'\x8216', '\x8217', // left single quote, right single quote
'x8211', '\x8212', // en-dash, em-dash
'\x0188', '\x0177', // 1/4 fraction, plus/minus
'\x8230', '\x0160' // ellipsis, non-breaking space
};
string[] charsToSubstituteForXMLLegality = new string[]
{ " ", " ", "", "-",
"\"", "\"", "\"",
"\'", "\'",
"-", "-",
"1/4", "+/-",
"...", " "
};
for (int i = 0; i < charsToRemoveForXMLLegality.Length; i++)
{
tempTxt = tempTxt.Replace(charsToRemoveForXMLLegality[i].ToString(), charsToSubstituteForXMLLegality[i]);
}
source to share