string比较失败
我是Ios开发的初学者,我试图比较两个平常而平等但比较失败的string,然后去看其他的东西:
NSString *response = [session.channel execute:@"gpio read 0" error:&error];//execute SSH command and write this one in log NSLog(response); if ([response isEqualToString:(@"1")]) { [session.channel execute:@"gpio write 0 0" error:&error]; } else { [session.channel execute:@"gpio write 0 1" error:&error]; }
这里是我的输出,响应等于1,但如果不使用:
2014-04-08 20:01:38.065 domotiqueRPI [36948:1303] NMSSH:Exec命令gpio读取0
2014-04-08 20:01:38.108 domotiqueRPI [36948:60b] 1
2014-04-08 20:01:38.109 domotiqueRPI [36948:1303] NMSSH:执行命令gpio写0 1
当然,我searchstackOverFlow,但它告诉我: 是使用isEqualToString方法
你在回应结束时有一个换行符。 尝试这个:
NSString *response = [session.channel execute:@"gpio read 0" error:&error]; response = [response stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
这将从响应string中删除尾随和前导空格/换行符。
顺便说一句 – 不需要@"1"
的括号。
- 在Swift中添加图像转换animation
- iOS / watchos2 – 为什么不会话:didReceiveApplicationContext:火?
- IOS模拟器问题的应用程序只运行时,第二次启动..
- 如何使用swift打印variablestypes数据的内容?
- Sqlite与iCloud同步不更新数据
- 使用CGAffineTransformMakeScale的UIViewanimation以十进制数字立即改变大小
- 自定义Google Sign In在GIDSignInDelegate协议上抛出exception
- 仅限于iPhone 5 / 5s / 5c的用户将AppStore的应用程序安装限制在内
- Firebase – iOS Swift:使用从两个单独的子节点中检索的数据加载表格视图单元格