title: NSData to NSString converstion problem!
body: <p>I'm getting an html file as NSData and need to parse it to extract some info. My approach was to convert it to NSString with UTF8 encoding (the html has non english characters, russian for example) - it failed. I used something like that:</p>
  
  <pre><code>NSString *respData = [NSString stringWithUTF8String:[theData bytes]];
  </code></pre>
  
  <p>but it returned nil. </p>
  
  <p>The only thing that actually worked was </p>
  
  <pre><code>[NSString stringWithCString:[theData bytes] length:[theData length]];
  </code></pre>
  
  <p>but when it encounters russian characters for example it returns jibrish.</p>
  
  <p>Then my next approach was to parse the byte array of the data, extract the bytes I need and somehow convert them to NSString. I tried something like that:</p>
  
  <pre><code>-(NSString *)UTF8StringFromData:(NSData *)theData{
   Byte *arr = [theData bytes];
   NSUInteger begin1 = [self findIndexOf:@"&lt;li&gt;" bArr:arr size:[theData length]]+4;
   NSUInteger end1 = [self findIndexOf:@"&lt;/li&gt;&lt;/ol&gt;" bArr:arr size:[theData length]];
   Byte *arr1 = (Byte *)malloc(sizeof(Byte)*((end1-begin1+1)));
   int j = 0;
   for (int i = begin1; i &lt; end1; i++){
    arr1[j] = arr[i];
    j++;
   }
   arr1[j]='\0';
   NSData *temp = [NSData dataWithBytes:arr1 length:j];
   return [[NSString alloc] initWithData:temp encoding:NSUTF8StringEncoding];
  }
  </code></pre>