1

I am using libiconv to convert array of char to encoded string. I am new to the library. I wonder how I can know what encoded type the given array is encoded in before I call iconv_open("To-be-encoded","given-encoded-type")

It's the second parameter that I need to know.

1
  • iconv_open needs to know them. You should already know them. You didn't mention what platform you're on, but I would suggest iconv --list from a terminal prompt on Unix with any reasonable iconv support. They are system-dependent. Example from OS X 10.10.1 Commented Jan 17, 2015 at 11:06

1 Answer 1

2

It's the second parameter that I need to know.

Yes, you indeed need to know it. I.e. it is you that needs to tell iconv what encoding your array is in. There is no reliable way of detecting what encoding was used to produce a set of bytes - at best you can take a guess based on character frequencies or other such heuristics.

But there is no way to be 100% sure without other information, from metadata or from the file/data format itself. (e.g. HTTP provides headers to indicate encoding, XML has that capability too.)

In other words, if you don't know how a stream of bytes you have is encoded, you cannot convert it to anything else. You need to know the starting point.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.