How to check the charset of string?

前端 未结 7 1726
心在旅途
心在旅途 2021-02-04 08:48

How do I check if the charset of a string is UTF8?

7条回答
  •  渐次进展
    2021-02-04 09:33

    Just a side note:

    You cannot determine if a given string is encoded in UTF-8. You only can determine if a given string is definitively not encoded in UTF-8. Please see a related question here:

    You cannot detect if a given string (or byte sequence) is a UTF-8 encoded text as for example each and every series of UTF-8 octets is also a valid (if nonsensical) series of Latin-1 (or some other encoding) octets. However not every series of valid Latin-1 octets are valid UTF-8 series.

提交回复
热议问题