'split하기'에 해당되는 글 2건

  1. 2010.11.06 [아이폰 앱 개발] NSString split하기
  2. 2010.10.12 [objective-c] NSString split하기
XCODE2010. 11. 6. 01:04
[아이폰 앱 개발] NSString split하기
<form name="search" action="http://www.idev101.com/search.html" method="POST">

Split a String into an Array

</form>

Split a string into an array of strings by using NSString's componentsSeparatedByString:

NSString *myString = @"This is a test"; NSArray *myWords = [myString componentsSeparatedByString:@" "]; // myWords is now: [@"This", @"is", @"a", @"test"]

If you need to split on a set of several different characters, use NSString's componentsSeparatedByCharactersInSet:

NSString *myString = @"Foo-bar/blee"; NSArray *myWords = [myString componentsSeparatedByCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"-/"] ]; // myWords is now: [@"Foo", @"bar", @"blee"]

The separator string can't be blank. If you need to separate a string into its individual characters, just loop through the length of the string and convert each char into a new string:

NSMutableArray *characters = [[NSMutableArray alloc] initWithCapacity:[myString length]]; for (int i=0; i < [myString length]; i++) { NSString *ichar = [NSString stringWithFormat:@"%c", [myString characterAtIndex:i]]; [characters addObject:ichar]; }

http://www.idev101.com/code/Objective-C/Strings/split.html
Posted by 오늘마감

댓글을 달아 주세요

오브젝트C2010. 10. 12. 04:51
[objective-c] NSString split하기
<form name="search" action="http://www.idev101.com/search.html" method="POST">

Split a String into an Array

</form>

Split a string into an array of strings by using NSString's componentsSeparatedByString:

NSString *myString = @"This is a test"; NSArray *myWords = [myString componentsSeparatedByString:@" "]; // myWords is now: [@"This", @"is", @"a", @"test"]

If you need to split on a set of several different characters, use NSString's componentsSeparatedByCharactersInSet:

NSString *myString = @"Foo-bar/blee"; NSArray *myWords = [myString componentsSeparatedByCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"-/"] ]; // myWords is now: [@"Foo", @"bar", @"blee"]

The separator string can't be blank. If you need to separate a string into its individual characters, just loop through the length of the string and convert each char into a new string:

NSMutableArray *characters = [[NSMutableArray alloc] initWithCapacity:[myString length]]; for (int i=0; i < [myString length]; i++) { NSString *ichar = [NSString stringWithFormat:@"%c", [myString characterAtIndex:i]]; [characters addObject:ichar]; }

http://www.idev101.com/code/Objective-C/Strings/split.html
Posted by 오늘마감

댓글을 달아 주세요