Tips for translating iOS development strings

Source: Internet
Author: User

/dictionary or array into nsstring

Nsarray *arr = [Nsarray arraywithobject:@ "1"];

NSString *str = [arr jsonstring]; Convert an array or dictionary into a JSON string

Nsarray *arr1 = [str objectfromjsonstring]; JSON string into a dictionary or array

NSData *data = [arr1 jsondata]; Convert the JSON string to NSData

NSString *STR1 = [[NSString alloc] initwithdata:data encoding:nsutf8stringencoding];//switch NSData to NSString
NSData *data1 = [str1 datausingencoding:nsutf8stringencoding]; Turn the nsstring into a nsdata

Binary flow becomes string

NSString *str=[[nsmutablestring alloc] initWithData:self.receiveDataencoding:NSUTF8StringEncoding];

Change the content

Str=[str stringbyreplacingoccurrencesofstring:@ "," withstring:@ ", \ n"];

Str=[str stringbyreplacingoccurrencesofstring:@ "{" withstring:@ "{\ n"];

Str=[str stringbyreplacingoccurrencesofstring:@ "}" withstring:@ "\ n}"];

NSLog (@ "%@", str);

Convert a string into a binary stream

Self.receivedata=[nsmutabledata Datawithdata:[str Datausingencoding:nsutf8stringencoding]];

Request changed to URL

Nsurl *url=[request URL];

URL changed to NSString

NSString *str=[[url absolutestring] stringbyreplacingpercentescapesusingencoding:nsutf8stringencoding];

NSLog (@ "%@", str);

Nsurl *url=[nsurl urlwithstring:@ "Http://img3.xooimage.com/files/6/1/3/firefox-logo-200x200-19f78a.png"];

Web site into a binary stream

Nsmutabledata *data=[nsmutabledata Datawithcontentsofurl:url];

UIImage *image=[uiimage Imagewithdata:data];

Read file

NSString *filepath = [[NSBundle mainbundle] pathforresource:@ "Students" oftype:@ "xml"];

File into a binary stream

NSData *data = [NSData Datawithcontentsoffile:filepath];

Take out the first letter

NSString *name = [City objectforkey:@ "name"];

NSString *firststr=[name substringwithrange:nsmakerange (0, 1)];

Remove an array directly from a string

NSString *str = [NSString stringwithformat:@ "Norman,stanley,fletcher"];

Nsarray *arr = [str componentsseparatedbystring:@ ","];

NSLog (@ "arr =%@", arr);

transcoding

URLSTR = [Urlstr stringbyaddingpercentescapesusingencoding:nsutf8stringencoding];

Tips for translating iOS development strings

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.