title: iOS:detect correct encoding of NSData
body: <p>I hava a <code>NSData</code> object which represents a <code>NSString</code> object. I use <code>-[NSString initWithData:encoding:]</code> to get the string. Now the problem is how do I know the correct encoding type?</p>
  
  <p>Thanks.</p>
  
  <p>Edited:
  I test and find: 
  the supposing the <code>NSData</code> is encoding with A, and I try to use encoding B to create the <code>NSString</code>. Sometimes the string will be nil, but string can be not nil which is a messy code. So I can't get the correct string by testing the each encoding type.</p>