为什么不是isEqualToString以我认为应该的方式工作? [英] Why doesn't isEqualToString work the way I think it should?

查看:98
本文介绍了为什么不是isEqualToString以我认为应该的方式工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将UTF-8编码的文本文件加载到数组中。在文本文件的几个地方有空行,没有空格。

I'm loading a UTF-8 encoded text file into an array. At several places in the text file there are blank lines, with no spaces.

在此条件中:

tempstring = [array objectAtIndex:index];
if( [tempstring isEqualToString:@""] == NO ) {
    // do something
}

结果始终为NO。我NSLog字符串,但我没有在空白行的控制台中看到任何字符。 NSLog还显示长度为1的空白行。

The result is always NO. I NSLog the strings, but I don't see any character in the console on the blank lines. The NSLog also shows the blank lines having the length of 1.

如何更正此条件才能生效?

How can I correct this conditional to work?

推荐答案

尝试从NSArray中删除NSString中的空格,然后再进行比较。请参阅此处:将空白区域的序列折叠为单个字符和修剪字符串

Try removing the whitespace from the NSString from the NSArray before comparing it. See here: Collapse sequences of white space into a single character and trim string

这篇关于为什么不是isEqualToString以我认为应该的方式工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆