Posts: 3,415
Threads: 158
Joined: Jan 2006
I am getting the following exception:
'Ã' is not representable in the encoding 'US-ASCII'
With this code snippet:
Code:
fileLogDump.FmtStr(strOutMessage);
fileLogDump.NewLn();
fileLogDump.Flush();
Is there an easy method to clean up non-Ascii characters out of a string before passing it to a TextOutStream?
BTW: This is in a Try/EndTry block and the exception is not getting caught...
Posts: 40,483
Threads: 491
Joined: Aug 2002
Are you getting a CML exceptoin and it's not getting cause by the Catch? Or is it some C++ exception leaking out because it wasn't correctly caught and translated?
On the other issue, perhaps you can just set a different encoding on the stream? Something like Latin1 (ISO-8859-1) is a full 256 code point encoding, so there won't be any invalid character issues, though if the source content is in some unusual encoding you may not get exactly the original text back.
Dean Roddey
Explorans limites defectum
Posts: 3,415
Threads: 158
Joined: Jan 2006
12-29-2012, 07:39 PM
(This post was last modified: 12-29-2012, 07:42 PM by wuench.)
It is a C++ exception not getting caught in the IDE. I don't see how to set the character set on a FileOutStream.
I tried to use an XCoder but I can't figure it out. If I put the string in a buffer and try to format it out to a string using a USASCII XCoder with the Error set to replace characters I get one exception and if I try to import it into a buffer using a USASCII XCoder I get a different exception. But at least those are caught so my code moves on.
But I have this string with that character in it. I have no idea what character set that is, it's coming in from XBMC via JSON. I want to write that string to a text file and filter out those characters or whatever it takes to write the string. Can you give me an example of how to do that?
Posts: 40,483
Threads: 491
Joined: Aug 2002
One of the class' constructors allows you to indicate an encoding. For string based text output streams, it doesn't matter since any text you have is Unicode and it's being written to a Unicode string buffer. But for files or memory buffers, it has to be converted to bytes and that requires that the text be transcoded to some encoding.
I'll look into why it's not catching the C++ exception and converting it.
Dean Roddey
Explorans limites defectum