NSTask 与 NSString 比较不起作用
我目前正在尝试将 shell 输出与字符串进行比较。 但这根本行不通!
StringOne = [[NSString alloc] initWithData:dataTwo encoding:NSUTF8StringEncoding];
if([StringOne isEqualToString:@"get if addr en0 failed, (os/kern) failure"])
{
NSLog(@"Failure!");
}
dataTwo 由 NSPipe 的 NSData 返回。 我几乎尝试了所有方法,但在互联网上找不到任何相关内容。
也许你可以帮助我。 谢谢!
编辑 事实证明,我试图比较的输出字符串带有换行符。 Hpf... 我刚刚在比较字符串末尾添加了“\n”,它起作用了!
Wo都应该从中吸取教训: 在网上发布之前检查你的东西两次:))
I'm currently trying to compare a shell output to a string.
But it won't work at all!
StringOne = [[NSString alloc] initWithData:dataTwo encoding:NSUTF8StringEncoding];
if([StringOne isEqualToString:@"get if addr en0 failed, (os/kern) failure"])
{
NSLog(@"Failure!");
}
The dataTwo is returned by a NSData from NSPipe.
I tried almost everything and couldn't find anything on the internet on that.
Maybe you can help me.
Thanks!
EDIT
It just turned out, that the output string, I'm trying to compare, is with newline. Hpf…
I just added "\n" at the end to my compare-string and it worked!
Wo should all learn from that:
Check your stuff twice before posting on the net :))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明,我的 shell 输出末尾有一个换行符。
我刚刚将“\n”添加到我的比较字符串中:
[StringOne isEqualToString:@"get if addr en0 failed, (os/kern) failure\n"]
现在它可以工作了!
It turned out, that my shell output had a newline at the end.
I just added "\n" to my compare string:
[StringOne isEqualToString:@"get if addr en0 failed, (os/kern) failure\n"]
Now it works!