---
title: "Convert UTF-8 encoded NSData to NSString，转载自stackoverflow"
author: "eleopard"
date: "2014-07-07T10:39:53Z"
tags: []
categories: ["编程语言"]
slug: "convert-utf-8-encoded-nsdata-to-nsstring-stackoverflow"
draft: false
lastmod: "2014-07-07T10:39:29Z"
id: 2088895
url: "https://eleopard.iteye.com/blog/2088895"
---

If the data is not null-terminated, you should use -initWithData:encoding:
NSString* newStr =  initWithData:theData encoding:NSUTF8StringEncoding];

If the data is null-terminated, you should instead use -stringWithUTF8String: to avoid the extra \0 at the end.
NSString* newStr = ];

转载地址：<http://stackoverflow.com/questions/2467844/convert-utf-8-encoded-nsdata-to-nsstring/2467856#2467856>