NSRangeFromStringテスト
2351 ワード
公式サイト
Returns a range from a textual representation.
SWIFT
Returns a range from a textual representation.
Declaration
SWIFT
func NSRangeFromString(_ aString
: String) -> NSRange
OBJECTIVE-C NSRange NSRangeFromString ( NSString *aString );
Discussion
Scans aString
for two integers which are used as the location and length values, in that order, to create an NSRange
struct. If aString
only contains a single integer, it is used as the location value. If aString
does not contain any integers, this function returns an NSRange
struct whose location and length values are both 0.
Availability
Available in iOS 2.0 and later.
、NSRangeFromStringによるバグを しました. にこのネーミングを てみましょう.この の が っています. ずかしいことに、この は の と さを すべきだと っていました.--#!テストの 、またドキュメントを て、やっと して、このようなことではありません!
NSString *str1 = @"abcdef";
NSString *str2 = @"1-105";
NSString *str3 = @"13";
NSString *str4 = @"13 34";
NSString *str5 = @"15 32 77";
NSRange range = NSRangeFromString(str1);
NSLog(@"
location:%ld length:%ld", range.location, range.length);
//location:0 length:0
range = NSRangeFromString(str2);
NSLog(@"
location:%ld length:%ld", range.location, range.length);
//location:1 length:105
range = NSRangeFromString(str3);
NSLog(@"
location:%ld length:%ld", range.location, range.length);
//location:13 length:0
range = NSRangeFromString(str4);
NSLog(@"
location:%ld length:%ld", range.location, range.length);
//location:13 length:34
range = NSRangeFromString(str5);
NSLog(@"
location:%ld length:%ld", range.location, range.length);
//location:15 length:32
apiを する に、ドキュメント、ドキュメント、ドキュメントを してください.