I have a string s
that receives a value from a database. Depending on which server is the database, the value comes in UTF-8
encoding or not and I can't control that.
My problem is that I need to find a way to only encode the value of the string s
with URLEncoder.encode(s, "UTF-8")
when that value is not UTF-8
, otherwise it gives me some unwanted characters.
I can't use juniversalchardet
to detect the encoding of the value.
How should I approach that to make sure I only encode when needed and get the correct value of the string?