Created
September 22, 2014 13:26
-
-
Save masuhara/0e34e86a674dea2a978a to your computer and use it in GitHub Desktop.
Yuka(Osaka School)'s Calculator program that can trim appropriate strings.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma mark - Check String (まっすーアルゴリズム) | |
- (NSString *)checkString:(NSString *)string | |
{ | |
NSRange searchResult = [string rangeOfString:@"="]; | |
NSString *numberString; | |
NSLog(@"string is %@", string); | |
if(searchResult.location == NSNotFound){ | |
// みつからない場合の処理 | |
NSLog(@"NOT FOUND"); | |
return string; | |
}else{ | |
// みつかった場合の処理 | |
NSLog(@"FIND"); | |
//スペースをトリミングする(うまくいってないかもw) | |
NSString *stringWithTrimmed = [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; | |
NSLog(@"stringWithTrimmed is %@", stringWithTrimmed); | |
//文字数を数える | |
int numberOfCharacter = [stringWithTrimmed length]; | |
NSLog(@"numberOfCharacter is %d", numberOfCharacter); | |
//「=」の位置を計算して、=よりあとの文字を切り出す。 | |
numberString = [stringWithTrimmed substringWithRange:NSMakeRange(searchResult.location, numberOfCharacter - searchResult.location)]; | |
NSLog(@"numberString is %@", numberString); | |
return numberString; | |
} | |
return nil; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment