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 오늘마감

댓글을 달아 주세요

아이폰어플개발정보2010. 10. 31. 03:10
[아이폰 앱 개발] NSString 스트링포맷 와일드카드써서 파일명바꾸기

int month;


for(month=1;month<13;month++){

NSString *imageName = [NSString stringWithFormat:@"2010_%d.png", month];

}


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 오늘마감

댓글을 달아 주세요

오브젝트C2010. 10. 12. 04:50
[objective-c] NSString 스트링포맷 와일드카드써서 파일명바꾸기

int month;


for(month=1;month<13;month++){

NSString *imageName = [NSString stringWithFormat:@"2010_%d.png", month];

}


Posted by 오늘마감

댓글을 달아 주세요

아이폰어플개발정보2010. 10. 5. 23:52
개발할때 참조할 NSString 기본적인 소스

//기본 스트링 작업

#import
#import
#import

int main (int argc, char *argv[])
{
NSAutoreleasePool *Pool = [[NSAutoreleasePool alloc] init];
NSString *str1 = @"This is string A";
NSString *str2 = @"This is string B";
NSString *res;
NSComparisonResult compareResult;

//문자 개수 세기
NSLog (@"Length of str1 : %lu", [str1 length]);

//스트링 복사하기
res = [NSString stringWithString : str2];
NSLog (@"Concatentation : %@", str2);

//두 개의 스트링이 같은지 비교
if ([str1 isEqualToString : res] == YES)
NSLog(@"str1 == res");
else
NSLog(@"str1 != res");

//두 개의 스트링 크기 비교
compareResult = [str1 compare : str2];

if (compareResult == NSOrderedAscending)
NSLog (@"str1 < str2");
else if (compareResult == NSOrderedSame)
NSLog (@"str1 == str2");
else    //NSOrderedDescending
NSLog (@"str1 > str2");

//대문자로 변환
res = [str1 uppercaseString];
NSLog (@"Uppercase conversion : %s", [res UTF8String]);

//소문자로 변환
res = [str1 lowercaseString];
NSLog (@"Lowercase conversion : %@", res);
NSLog (@"Original string : %s", str1);

[pool drain];
return 0;

}



출처 : http://blog.naver.com/PostList.nhn?blogId=hana_815¤tPage=60
Posted by 오늘마감

댓글을 달아 주세요

아이폰어플개발정보2010. 9. 17. 00:01
NSString 값 비교하기..

좀 짜증나 죽는줄 알았음.

NSString *str = [(UIButton *) sender currentTitle];

if ( str == @"Start")

{

}

이렇게 코딩하니까

if문을 타지 않음..내가 오브젝트C에 대해 이해를 덜하고 있었나.

그동안 나의 코딩 실력이 없었던 것일까..많은 고민함.

근데 보니까. str은 오브젝트임. @"Start"는 문자열임

당연히 == 는 성립할 수 없음.

그래서 메소드가 있겠구나~하고 메소드를 찾아봄

if([str isEqualToString:@"Start"])

{

}

이렇게 하면 되는것임.

역시..오브젝트는 어려움ㅠㅠ



출처 : http://blog.naver.com/PostList.nhn?blogId=heajin722¤tPage=24
Posted by 오늘마감

댓글을 달아 주세요

아이폰어플개발정보2010. 6. 24. 11:34
파일에 NSString 저장하기

by srudenko 26. 3월 2010 12:04
//Method writes a string to a text file


-(void) writeToTextFile{


 //get the documents directory:

 NSArray *paths = NSSearchPathForDirectoriesInDomains


 (NSDocumentDirectory, NSUserDomainMask, YES);

 NSString *documentsDirectory = [paths objectAtIndex:0];

 //make a file name to write the data to using the documents directory:

 NSString *fileName = [NSString stringWithFormat:@"%@/textfile.txt",

   documentsDirectory];

 //create content - four lines of text

 NSString *content = @"One\nTwo\nThree\nFour\nFive";


 //save content to the documents directory

 [content writeToFile:fileName  atomically:NO

   encoding:NSStringEncodingConversionAllowLossy

   error:nil];

}



출처 : http://blog.naver.com/PostView.nhn?blogId=amoros21&logNo=140107110949
Posted by 오늘마감

댓글을 달아 주세요