6

Is it possible? I want to check if a string is utf-8 encoded.

UPDATE: So, the problem is: I have a php webservice. This webservice has a method that receives a string. I'm trying to pass a VB.NET JSON string to this webservice. json_decode always returns an error, saying that the string is not utf-8. If I pass the string and convert it using PHP utf8_encode, the accents get wrong! How could I solve that?

Luke Girvin
  • 13,221
  • 9
  • 64
  • 84
thom
  • 85
  • 2
  • 2
  • 5
  • How does your string look like? `byte[]`? – abatishchev May 17 '11 at 19:27
  • I've made this, but i don't know if it's alright: http://stackoverflow.com/questions/6035380/vb-net-encode-string-to-utf-8 . Thank you. – thom May 17 '11 at 19:29
  • 2
    A `System.String` is never UTF-8. It's UTF-16. Only the byte representation of a string can be UTF-8. – CodesInChaos May 17 '11 at 19:50
  • 1
    Possible duplicate of [Determine a string's encoding in C#](http://stackoverflow.com/questions/1025332/determine-a-strings-encoding-in-c-sharp) – Luke Girvin Oct 24 '16 at 08:51
  • See also http://stackoverflow.com/questions/18915633/determine-textfile-encoding – Luke Girvin Oct 24 '16 at 08:55
  • The only way I think will work without any third party tools is to just iterate over the byte array and test if it matches a known encoding. A great article with this is posted @ http://www.mobzystems.com/code/detecting-text-encoding.aspx – Frazell Thomas May 17 '11 at 19:34
  • This article ^^^ applies only when input byte[] has a Preamble setup already. Pretty much that is when the creator of the stream "tells" you what the encoding is. Is not answering the OP question. – Dan M May 08 '17 at 18:30

0 Answers0