-
-
Save azurestone/3793561 to your computer and use it in GitHub Desktop.
空の要素を切り詰める処理
This file contains hidden or 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
#import <Foundation/Foundation.h> | |
// gcc -framework Foundation XX.m -o XX.exe | |
int main(int argc, const char *argv[]){ | |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | |
// STEP1 普通にjoinする(空の要素がない場合) | |
NSArray *array_part_a = [NSArray arrayWithObjects:@"1",@"2",@"3", @"4", @"5", @"6", nil]; | |
NSString *string_a = [array_part_a componentsJoinedByString:@" / "]; | |
NSLog(@"%@\n\n", string_a); | |
// STEP2 普通にjoinする(空の要素がある場合) | |
NSArray *array_part_b = [NSArray arrayWithObjects:@"1",@"",@"3", @"", @"5", @"6", nil]; | |
NSString *string_b = [array_part_b componentsJoinedByString:@" / "]; | |
NSLog(@"%@\n\n", string_b); | |
// STEP3 | |
NSMutableArray *new_array = [[NSMutableArray alloc]init]; | |
for (NSString *temp_str in array_part_b){ | |
if (temp_str == nil || [temp_str isEqualToString:@""]) { | |
// No Job... | |
} | |
else { | |
[new_array addObject:temp_str]; | |
} | |
} | |
NSString *string_c = [new_array componentsJoinedByString:@" / "]; | |
NSLog(@"%@\n\n",string_c); | |
[pool drain]; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment