Common methods of NSString in Foundation

Source: Internet
Author: User

1. Case operation
 //  all uppercase    result ABC  [@ " ABC    uppercasestring]  //  all lowercase  //  result BCD  [@ " bcd   "  lowercasestring]  //  first uppercase  //  result ACB  [@ " ACB  "  Capitalizedstring] 
2. String comparisons
//Compare two strings for the same contentbool b =[str isequaltostring:str2];  
// Two string content comparison //< Span style= "color: #008000;" > Nscomparisonresult result = {nsorderedascending, nsorderedsame,nsordereddescending } // nsorderedascending right > left // Nsorderedsame content same // nsordereddescending left > right Nscomparisonresult Result = [str compare:str2]; ignore case to compare
nscomparisonresult result = [str CASEINSENSITIVECOMPARE:STR2];
3. String Search
//determines whether a string starts with ABC[@ "ABCDFA"Hasprefix:@ "ABC"]; //determines whether a string is a BCD end[@ "ADBCD"Hassuffix:@ "BCD"]; //determines whether the string contains the specified string, returns the position and lengthNsrange range = [@ "123456"Rangeofstring:@ "456"]; //Reverse SearchNsrange range = [@"123456456qweasasd456"Rangeofstring:@"456"Options:nsbackwardssearch]; //Search by specified rangeNsrange range = Nsmakerange (0,9); Range= [@"123456456qweasasd456"Rangeofstring:@"456"Options:nsbackwardssearch Range:range];

Common methods of NSString in Foundation

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.