I ve一只 st倒在ASCIIEncoding。 用黑体取代无效特性吗? 我对此感到非常困惑,因为这样一来就打破了至少令人惊讶的规则。 在Zalar,将使用u”some unicode string.encode(ascii)
,而转换则因违约而严格,因此,非ASCII特性将产生这一例外情况。
两个问题:
- How can strings be strictly converted to another encoding (like ASCII or Windows-1252), so that an exception is thrown if invalid characters occur? By the way I don t want a foreach loop converting each Unicode number to a byte, and then checking the 8th bit. This is supposed to be done by a great framework like .NET (or Python ^^).
- Any ideas on the rationale behind this default behavior? For me, it makes more sense to do strict conversions by default or at least define a parameter for this purpose (Python allows "replace", "ignore", "strict").