我在比较 Objective C 中的 NSStrings 时遇到了一些麻烦。我查看了苹果文档,似乎有一个函数返回一个名为 isEqualToString 的布尔值。但是,该语句永远不会执行。
NSString* randomCombo = @"rypo";
NSFileHandle* kbd = [NSFileHandle fileHandleWithStandardInput];
NSData* inputData = [kbd availableData];
NSString* line = [[NSString alloc]initWithData : inputData encoding : NSUTF8StringEncoding];
NSLog(@"You entered: %@", line);
NSLog(@"The string to match is: %@", randomCombo);
if([line isEqualToString : randomCombo]){
NSLog(@"you win.");
}
我需要对 NSString、randomCombo 进行编码吗?有人能帮我弄清楚这里出了什么问题吗?
When you use return to end your input, there's a newline character appended to the string which the other string doesn't have.
You need to either terminate input using control-D, which just closes the pipe without starting a new line, or trim the '\n'
off of the string afterwards.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)