【发布时间】:2014-07-15 17:01:22
【问题描述】:
public string OpenDialogueFile(string dialogueName) {
if(dialogues == null) {
dialogues = Resources.LoadAll<TextAsset>("Dialogue");
}
var text = "";
foreach(var ta in dialogues) {
print(ta.name + ".." + dialogueName);
if(ta.name == dialogueName) {
print("Found");
text = ta.text;
break;
}
}
return text;
}
这段代码应该找到一个具有请求名称的纯文本文件并吐出内容。
Resources/Dialogue 中的文件“test1 和 test2”并请求 test1,输出为
test1..test1
Found
但是,当请求 test2 时
test1..test2
test2..test2
程序声称 test2 不等于 test2。
ta.name 和 dialogName 都是字符串,所以它应该是按内容测试相等性。
我的相等操作有问题吗?
【问题讨论】:
-
ta.name是否声明为字符串? -
任一字符串末尾是否有空格?
-
如果你这样做
print("\"" + ta.name + ".." + dialogueName + "\"");,你的输出会得到什么 -
编码是什么?你确定你只是在这里比较 ASCII 和 ASCII 而不是看起来像“test2”的东西吗?