Check if a String contains encoded characters

前端 未结 6 1046
情深已故
情深已故 2020-12-18 08:46

Hello I am looking for a way to detect if a string has being encoded

For example

    String name = \"Hellä world\";
    String encoded = new String(n         


        
6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-18 09:40

    I'm not really sure what are you trying to do or what is your problem.

    This line doesn't make any sense:

    String encoded = new String(name.getBytes("utf-8"), "iso8859-1");
    

    You are encoding your name into "UTF-8" and then trying to decode as "iso8859-1".

    If you what to encode your name as "iso8859-1" just do name.getBytes("iso8859-1").

    Please tell us what is the problem you encountered so that we can help more.

提交回复
热议问题