IOS NSString intercept strings (intercepted by index)

Source: Internet
Author: User

1. rangeofstring: Intercept the length of the specified string; 2. substringToIndex:7:截取从0 索引到指定索引(7)长度的字符串 (从0到7)
3. substringFromIndex:9:截取从指定索引(9)到末尾长度的字符串  (从9到0)
4. substringWithRange:NSMakeRange(4,2):截取从指定索引(4)到指定(2)长度的字符串 (从4开始后的2个)
5. isEqualToString:@"p://www":比较字符串包含关系,区分大小写
6. stringWithFormat:格式化字符串。
I. Define a string A, intercept a project group of a, copy to B, B must be of type int

NSString *a = @ "1.2.30";

int b= [[a Substringwithrange:nsmakerange (4,2)] intvalue];

NSLog (@ "a:%@ \ n", a);

NSLog (@ "b:%d", b);

output:2011-07-05 11:49:08.170 q[4005:207] a:1.2.30

2011-07-05 11:49:08.172 q[4005:207] b:30

The parsing is as follows: Substringwithrange: A piece of string specifically intercepted

Nsmakerange (4,2) from the beginning of the 4th character intercept, the length of 2 characters, (the string is the beginning of the No. 0 character of the first number OH ~!) )

Two. String intercept to Nth bit (substringtoindex:n) (nth bit not counted)

NSString *a = @ "I like long dress";

NSString *b = [a substringtoindex:4];

NSLog (@ "B:%@", b);

2011-07-11 18:12:40.119 q[6321:207] b:i Li

Three. The string is truncated from the beginning of the nth bit until the last (substringfromindex:n) (contains nth bits)

NSString *a = @ "I like long dress";

NSString *b = [a substringfromindex:4];

NSLog (@ "B:%@", b);

2011-07-11 18:15:08.125 q[6366:207] b:ke long dress

IOS NSString intercept strings (intercepted by index)

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.