title: How to reconstruct a String correctly from a String which be encoded by wrong charset
body: <p><strong>Edit</strong> Added some new information to make the question more clearly.</p>
  
  <p>In matlab early before 2012B, the method <code>urlread</code> would return a string constructed by wrong charset if the web content's charset is not utf8. (It has been improved somewhat in Matlab 2012B)</p>
  
  <p>For example</p>
  
  <pre><code>% a chinese website whose content encoding by gb2312
  url = 'http://www.cnbeta.com/articles/213618.htm'; 
  html = urlread(url)
  </code></pre>
  
  <p>Because Matlab encoded the html using utf8 instead of gb2312.
  You will see the chinese character in the html doesnot show correctly.</p>
  
  <p>If I read a chinese website with utf8 encoded, then everything works fine:</p>
  
  <pre><code>% a chinese website whose content encoding by utf8
  url = 'http://www.baidu.com/'; 
  html = urlread(url)
  </code></pre>
  
  <p>So is there any way to reconstruct the string correctly from html?
  I have tried as  following, but it didnot work:</p>
  
  <pre><code>&gt;&gt; bytes = unicode2native(html,'utf8');
  &gt;&gt; str = native2unicode(bytes,'gb2312')
  </code></pre>
  
  <p>However, I do known there is a way to fix the <code>urlread</code>'s problem: 
  Type <code>edit urlread.m</code> in the console and then replace the code nearly Line 108 (In matlab 2011B):</p>
  
  <pre><code>output = native2unicode(typecast(byteArrayOutputStream.toByteArray','uint8'),'UTF-8');
  </code></pre>
  
  <p>by:</p>
  
  <pre><code>output = native2unicode(typecast(byteArrayOutputStream.toByteArray','uint8'),'gb2312');
  </code></pre>
  
  <p>Save the file, and now <code>urlread</code> would works for website encoded by gb2312.
  Actually, this solution point out why <code>urlread</code> doesnot work sometime. The method <code>urlread</code> always use the utf8 charset to encode string even if the content is not encoded by utf8.</p>