如何识别和删除换行符和空格? [英] How to identify and remove newline and white spaces?
本文介绍了如何识别和删除换行符和空格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在通过按组件分隔字符串来创建一个 nsmutable 数组,这会导致在数组中插入大量新行和空格,如何识别和删除它们?
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
推荐答案
如果你想要一个没有空格的数组:
If you want an array without whitespace:
NSString *string = @"Hello, World!";
NSCharacterSet *separator = [NSCharacterSet whitespaceAndNewlineCharacterSet];
NSArray *stringComponents = [string componentsSeparatedByCharactersInSet:separator];
这篇关于如何识别和删除换行符和空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文