How can I insert ASCII special characters (e.g. with the ASCII value 0x01) into a string?I ask because I am using the following:str.Replace( "<TAG1>", Convert.ToChar(0x01).ToString() );and I feel that there must be a better way than this. Any Ideas?Update:Also If I use this methodology, do I need to worry about unicode & ASCII clashing?
Does the hex value after the '\u' represent an ASCII character?
It will, if the number is below 0x80.
'\u0001' is a valid Unicode code point. Text/Binary is a matter of semantics.
SebastianGodelet, not really. Unicode code points are mapped only to bytes by a Unicode translation format. For the example above, the Unicode code point u+0001 is represented by the byte 0x01 in some translation formats. So technically, when manipulating a binary chunk, you could figure out what combination of code point and translation format would map to the binary sequence you want to insert - if there is such a combination. Hardly semantics. :)
well but the OP is operating on a string already. SO he should hopefully not put binary data into a string to start with. And as the .NET string is using UTF-16, the \u0001 is a valid byte sequence describing the very same ASCII control character.
SebastianGodelet, the OP is only technically operating on a string. What they're really trying to do is put binary data into a string, for example the value "0x01". For <TAG2>, the OP would put in 0x02, and so on. (On a side note, the fact that .NET uses UTF-16 internally isn't relevant here - the OP's example will do what you say because of howConvert.ToChar() works, treating the argument as a Unicode code point number.)