Other [SOLVED] Lack of knowledge: getting the string encoding

Discussion in 'Android Questions' started by lemonisdead, Jun 3, 2015.

  1. lemonisdead

    lemonisdead Well-Known Member Licensed User

    Hello,

    I am asking for a little help about how to get the default string encoding or a link about. The need is to distinguish which is ASCII and which is UTF-8.

    Is the best solution to convert the string to ASCII, reencode it and compare it with the original ? That's what I did but sometimes I don't get the real string's length.

    This is to be able to know its length in Bytes (about like the problem for the SMS length).

    Any help really appreciated. Many thanks
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    There is no simple way to get the string encoding. The same raw bytes can be valid strings in many different encodings.

    If you are only interested in ASCII vs. UTF8 then you can test whether all the bytes are between 0 to 127. In that case you can safely treat it as ASCII string.
     
    lemonisdead and Peter Simpson like this.
  3. lemonisdead

    lemonisdead Well-Known Member Licensed User

    Hello Erel,
    Thanks a lot for the idea. It will solve my need for sure. Great :)
     
Loading...