I want to import a row-by-row file into an array. I want to get rid of all the spaces before and after the lines so that I can compare the lines a lot easier without having inconsistencies due to the small spaces in the spaces. I have NSData file contents and then take two lines
NSString* string = [[[NSString alloc] initWithBytes:[data bytes] length:[data length] encoding:NSUTF8StringEncoding] autorelease]; NSString* string2 = [[[NSString alloc] initWithBytes:[data2 bytes] length:[data2 length] encoding:NSUTF8StringEncoding] autorelease];
I tried to do this to remove the space before adding to the array, but it does not work.
NSString *newString = [string stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceCharacterSet]]; NSString *newString2 = [string2 stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceCharacterSet]]; NSArray *fileInput = [newString componentsSeparatedByString:@"\n"]; NSArray *fileInput2 = [newString2 componentsSeparatedByString:@"\n"];
source share