Developer Library에 있는 내용이지만, 그 중에서 하나씩 가져와서 잘 쓰는 기능에 대해서 정리합니다.
Creating and Initializing Strings
+ string– init– initWithBytes:length:encoding:– initWithBytesNoCopy:length:encoding:freeWhenDone:– initWithCharacters:length:– initWithCharactersNoCopy:length:freeWhenDone:– initWithString:– initWithCString:encoding:– initWithUTF8String:– initWithFormat:- : 데이터 포멧으로 문자열을 만듭니다.
– initWithFormat:arguments:– initWithFormat:locale:– initWithFormat:locale:arguments:– initWithData:encoding:+ stringWithFormat:+ localizedStringWithFormat:+ stringWithCharacters:length:+ stringWithString:+ stringWithCString:encoding:+ stringWithUTF8String:- : NSData에서 bytes함수로 읽어서 NSString을 만들 수 있음.
- : [NSString stringWithUTF8String:[myData bytes]];
+ stringWithCString:Deprecated in OS X v10.4+ stringWithCString:length:Deprecated in OS X v10.4– initWithCString:Deprecated in OS X v10.4– initWithCString:length:Deprecated in OS X v10.4– initWithCStringNoCopy:length:freeWhenDone:Deprecated in OS X v10.4
Creating and Initializing a String from a File
+ stringWithContentsOfFile:encoding:error:– initWithContentsOfFile:encoding:error:+ stringWithContentsOfFile:usedEncoding:error:– initWithContentsOfFile:usedEncoding:error:+ stringWithContentsOfFile:Deprecated in OS X v10.4– initWithContentsOfFile:Deprecated in OS X v10.4
Creating and Initializing a String from an URL
+ stringWithContentsOfURL:encoding:error:– initWithContentsOfURL:encoding:error:+ stringWithContentsOfURL:usedEncoding:error:– initWithContentsOfURL:usedEncoding:error:+ stringWithContentsOfURL:Deprecated in OS X v10.4– initWithContentsOfURL:Deprecated in OS X v10.4
Writing to a File or URL
– writeToFile:atomically:encoding:error:– writeToURL:atomically:encoding:error:– writeToFile:atomically:Deprecated in OS X v10.4– writeToURL:atomically:Deprecated in OS X v10.4
Getting a String’s Length
Getting Characters and Bytes
– characterAtIndex:- : index위치의 문자를 리턴
– getCharacters:range:– getBytes:maxLength:usedLength:encoding:options:range:remainingRange:– getCharacters:Deprecated in OS X v10.6
Getting C Strings
– cStringUsingEncoding:– getCString:maxLength:encoding:– UTF8String– cStringDeprecated in OS X v10.4– cStringLengthDeprecated in OS X v10.4– getCString:Deprecated in OS X v10.4– getCString:maxLength:Deprecated in OS X v10.4– getCString:maxLength:range:remainingRange:Deprecated in OS X v10.4– lossyCStringDeprecated in OS X v10.4
Combining Strings
– stringByAppendingFormat:– stringByAppendingString:- : 두개의 스트링을 합쳐서 새로운 스트링을 만들 때 사용합니다.
- 만약 하나의 스트링에 계속 추가하려면, NSMutableString을 사용하면 됩니다.
– stringByPaddingToLength:withString:startingAtIndex:
Dividing Strings
– componentsSeparatedByString:- - (NSArray *)componentsSeparatedByString:(NSString *)separator: String에서 특정 문자나 문자열로 구분되는 스트링들을 가져올 때 사용합니다.@"=" 문자열로 나뉘는 문자열 배열을 받아 올 수 있습니다.
– componentsSeparatedByCharactersInSet:- : [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
– stringByTrimmingCharactersInSet:– substringFromIndex:– substringWithRange:– substringToIndex:
Finding Characters and Substrings
– rangeOfCharacterFromSet:– rangeOfCharacterFromSet:options:– rangeOfCharacterFromSet:options:range:– rangeOfString:– rangeOfString:options:– rangeOfString:options:range:– rangeOfString:options:range:locale:– enumerateLinesUsingBlock:- - (void)enumerateLinesUsingBlock:(void (^)(NSString *line, BOOL *stop))block: 문자열에 있는 라인별로 블록을 실행합니다. stop에 YES를 입력하면, iteration을 멈추게 됩니다.line - 현재 라인의 문자열stop - enumeration을 멈추기 위한 BOOL 값, (
*stop = YES;) – enumerateSubstringsInRange:options:usingBlock:
Replacing Substrings
– stringByReplacingOccurrencesOfString:withString:- - (NSString *)stringByReplacingOccurrencesOfString:(NSString *)target withString:(NSString *)replacement
: 문자열을 찾아서 다른 문자열로 대체합니다.Space를 찾아서 제거할 수 있습니다.
[string stringByReplacingOccurrencesOfString:@" " withString:@""]
– stringByReplacingOccurrencesOfString:withString:options:range:– stringByReplacingCharactersInRange:withString:
Determining Line and Paragraph Ranges
– getLineStart:end:contentsEnd:forRange:– lineRangeForRange:– getParagraphStart:end:contentsEnd:forRange:– paragraphRangeForRange:
Determining Composed Character Sequences
Converting String Contents Into a Property List
Identifying and Comparing Strings
– caseInsensitiveCompare:– localizedCaseInsensitiveCompare:– compare:– localizedCompare:– compare:options:– compare:options:range:– compare:options:range:locale:– localizedStandardCompare:– hasPrefix:– hasSuffix:– isEqualToString:– hash
Folding Strings
Getting a Shared Prefix
Changing Case
– capitalizedString– capitalizedStringWithLocale:– lowercaseString– lowercaseStringWithLocale:– uppercaseString– uppercaseStringWithLocale:
Getting Strings with Mapping
– decomposedStringWithCanonicalMapping– decomposedStringWithCompatibilityMapping– precomposedStringWithCanonicalMapping– precomposedStringWithCompatibilityMapping
Getting Numeric Values
Working with Encodings
+ availableStringEncodings+ defaultCStringEncoding+ localizedNameOfStringEncoding:– canBeConvertedToEncoding:– dataUsingEncoding:– dataUsingEncoding:allowLossyConversion:– description– fastestEncoding– smallestEncoding
Working with Paths
+ pathWithComponents:– pathComponents– completePathIntoString:caseSensitive:matchesIntoArray:filterTypes:– fileSystemRepresentation– getFileSystemRepresentation:maxLength:– isAbsolutePath– lastPathComponent– pathExtension– stringByAbbreviatingWithTildeInPath– stringByAppendingPathComponent:– stringByAppendingPathExtension:– stringByDeletingLastPathComponent– stringByDeletingPathExtension– stringByExpandingTildeInPath– stringByResolvingSymlinksInPath– stringByStandardizingPath– stringsByAppendingPaths:
Working with URLs
– stringByAddingPercentEscapesUsingEncoding:– stringByReplacingPercentEscapesUsingEncoding:– stringByAddingPercentEncodingWithAllowedCharacters:– stringByRemovingPercentEncoding
Linguistic Tagging and Analysis
위 내용은 Develper Libarary에 있는 내용을 사용하면서, 쓰임새를 정리한 것입니다.
0 comments:
댓글 쓰기