The data could not be converted to text with this encoding

Using 2019 3.2

How can I find this character that is causing this:

Unhandled RuntimeException
Message: The data could not be converted to text with this encoding.

I’m putting it in a list box:
lstProviders.Cell(lstProviders.LastIndex, 2) = rs.Field(“Title”).StringValue.UTF8

This was working fine. Nothing is jumping out at me looking at the data.

Thanks

Can you post the offending Title as hex?

var h as string = EncodeHex( rs.Field( "Title" ).StringValue )

That’s the problem, I can’t figure out what the offending text is…

Found it, it was the special “-” in word.

Is there a way to filter these weird characters out?

Try CheckUTF8MBS.

It should still be able to be converted to UTF8 though. If you’re trying to DefineEncoding, it means the original encoding is not UTF-8.

My M_String module has a function, MakeValidUTF8, that might help you.

is that a non-breaking hyphen?

Could you show us the contents of your UTF8 method?

It was that hyphen from word, the em dash, but I found it and removed it.

Is there a way I can filter it out?

Can you use TextEncoding.IsValidData?

Not familiar with that, @Greg_O_Lone, what do you think?