I am making an nsmutable array by separating a string by component it is causing a lot of new line and white spaces to be inserted in the array how to identify and remove them?
for (int i=0;i<contentsOfFile.count; i++)
{
if(!([[contentsOfFile objectAtIndex:i]isEqual:@"\n"]||[[contentsOfFile objectAtIndex:i]isEqual:@""]))
[arrayToBereturned addObject:[contentsOfFile objectAtIndex:i]];
}
this code which i am using cannot identify all new line charectors thanks
To remove all white spaces from String, use the replaceAll() method of String class with two arguments, i.e. Program: Java.
trim() method removes the leading and trailing spaces present in the string. strip() method removes the leading and trailing spaces present in the string. Also, it is Uniset/Unicode character aware.
In JavaScript, trim() is a string method that is used to remove whitespace characters from the start and end of a string. Whitespace characters include spaces, tabs, etc. Because the trim() method is a method of the String object, it must be invoked through a particular instance of the String class.
Remove white space using font-size We can also remove white space by setting parent element font-size to 0 and child elements font-size to 17px .
To remove all extra space and \n from your string-
NSString* result = [yourString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
than prepare your contentsOfFile Array.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With