IOS 9.0 nsstring Kanji how to survive UTF8
Last Update:2016-01-19
Source: Internet
Author: User
<span id="Label3"></p><p style="color: #333333; font-size: 14px; line-height: 26px; margin-top: 0px; margin-bottom: 0px;"><p style="color: #333333; font-size: 14px; line-height: 26px; margin-top: 0px; margin-bottom: 0px;"><span style="font-family: Menlo; color: #703daa;">NSString<span style="font-family: Menlo;"> *str = <span style="color: #d12f1b;"><span style="font-family: Menlo;">@ " <span style="font-family: Heiti SC Light;">I am a good person <span style="font-family: Menlo; color: #d12f1b;">"<span style="font-family: Menlo;">;</span> </span> </span> </span></span> </span></span></p></p><span style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px;"><span style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px;"><span style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px;">before turning this into a UTF8, we used</span></span></span><p style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px;"><p style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px;"></p></p><p style="color: #333333; font-size: 14px; line-height: 26px; margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><p style="color: #333333; font-size: 14px; line-height: 26px; margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><span style="color: #703daa;">NSString *STR3 = [str stringbyaddingpercentescapesusingencoding:</span></p></p><p style="font-size: 14px; line-height: 26px; margin-top: 0px; margin-bottom: 0px; font-family: Menlo; color: #3d1d81;"><p style="font-size: 14px; line-height: 26px; margin-top: 0px; margin-bottom: 0px; font-family: Menlo; color: #3d1d81;">nsutf8stringencoding];</p></p><p style="color: #333333; font-size: 14px; line-height: 26px; margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><p style="color: #333333; font-size: 14px; line-height: 26px; margin-top: 0px; margin-bottom: 0px; font-family: Menlo;">But in ios9, this method is Obsolete.</p></p><p style="color: #333333; font-size: 14px; line-height: 26px; margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><p style="color: #333333; font-size: 14px; line-height: 26px; margin-top: 0px; margin-bottom: 0px; font-family: Menlo;">Use the following method to turn</p></p><p style="color: #333333; font-size: 14px; line-height: 26px; margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><p style="color: #333333; font-size: 14px; line-height: 26px; margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"></p></p><p style="font-size: 14px; line-height: 26px; margin-top: 0px; margin-bottom: 0px; font-family: Menlo; color: #3d1d81;"><p style="font-size: 14px; line-height: 26px; margin-top: 0px; margin-bottom: 0px; font-family: Menlo; color: #3d1d81;"><span style="color: #000000;"><span style="color: #703daa;">nsstring<span style="color: #000000;"> *str1 = [str stringbyaddingpercentencodingwithallowedcharacters<span style="color: #000000;">: [<span style="color: #703daa;">nscharacterset <span style="color: #000000;"> Urlqueryallowedcharacterset<span style="color: #000000;">]];</span> </span> </span> </span> </span> </span></span></p></p><p style="color: #333333; font-size: 14px; line-height: 26px; margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><p style="color: #333333; font-size: 14px; line-height: 26px; margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><br></p></p><p style="color: #333333; font-size: 14px; line-height: 26px; margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><p style="color: #333333; font-size: 14px; line-height: 26px; margin-top: 0px; margin-bottom: 0px; font-family: Menlo;">What if you want to turn into a " <span style="color: #d12f1b; font-family: ‘Heiti SC Light‘; font-size: 14px; line-height: 26px;">I'm a good person" string, don't worry about a way.</span></p></p><p style="color: #333333; font-size: 14px; line-height: 26px; margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><p style="color: #333333; font-size: 14px; line-height: 26px; margin-top: 0px; margin-bottom: 0px; font-family: Menlo;">Or is that the way we used to be</p></p><p style="color: #333333; font-size: 14px; line-height: 26px; margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><p style="color: #333333; font-size: 14px; line-height: 26px; margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"></p></p><p style="font-size: 14px; line-height: 26px; margin-top: 0px; margin-bottom: 0px; font-family: Menlo; color: #3d1d81;"><p style="font-size: 14px; line-height: 26px; margin-top: 0px; margin-bottom: 0px; font-family: Menlo; color: #3d1d81;"><span style="color: #703daa;">NSString<span style="color: #000000;"> *str3 = [str1 stringbyreplacingpercentescapesusingencoding<span style="color: #000000;">: nsutf8stringencoding<span style="color: #000000;">];</span> </span> </span></span></p></p><p style="font-size: 14px; line-height: 26px; margin-top: 0px; margin-bottom: 0px; font-family: Menlo; color: #3d1d81;"><p style="font-size: 14px; line-height: 26px; margin-top: 0px; margin-bottom: 0px; font-family: Menlo; color: #3d1d81;"><span style="color: #000000;"><br></span></p></p><p style="color: #333333; font-size: 14px; line-height: 26px; margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><p style="color: #333333; font-size: 14px; line-height: 26px; margin-top: 0px; margin-bottom: 0px; font-family: Menlo;">iOS9 also abandoned this method now used</p></p><p style="color: #333333; font-size: 14px; line-height: 26px; margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><p style="color: #333333; font-size: 14px; line-height: 26px; margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"></p></p><p style="font-size: 14px; line-height: 26px; margin-top: 0px; margin-bottom: 0px; font-family: Menlo; color: #3d1d81;"><p style="font-size: 14px; line-height: 26px; margin-top: 0px; margin-bottom: 0px; font-family: Menlo; color: #3d1d81;"><span style="color: #703daa;">NSString<span style="color: #000000;"> *str2 = [str1 stringbyremovingpercentencoding<span style="color: #000000;">];</span> </span></span></p></p><p><p>IOS 9.0 nsstring Kanji how to survive UTF8</p></p></span>