String processing for iOS: intercepting strings, matching strings, separating strings

Source: Internet
Author: User

1, the Interception of strings

//1. Intercepting StringsNSString*string=@"123456d890"; NSString*STR1 = [stringSubstringtoindex:5];//intercept the string before the drop Mark 5NSLog (@"The Intercept value is:%@", STR1); NSString*STR2 = [stringSubstringfromindex:3];//intercept the string after the drop Mark 3NSLog (@"The Intercept value is:%@", str2);

2. Match string

Finds (matches) a string (Ad) from a string (SD is SFSFSADFSDF)

//2. Matching stringsNSString *string=@"SD is SFSFSADFSDF"; Nsrange Range= [stringRangeofstring:@ "Ad"];//match the resulting subscriptNSLog (@"rang:%@", Nsstringfromrange (range));string= [stringSubstringwithrange:range];//intercept a string within a rangeNSLog (@"The Intercept value is:%@",string);

3. String segmentation

To split a string based on a character (a) in a string
// 3. Separating strings NSString *String =@ "sdfsfsfsadfsdf";     *array = [string componentsseparatedbystring:@ "A"//  An array of 2 elements separated from character a NSLog (@ "array:%@"// result is ADFSFSFS and DFSDF 

String processing for iOS: intercepting strings, matching strings, separating strings

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.