- Home /
How can I get a string to work as the key to a dictionary filled with the text of a www object?
I used the WWW Class to get a text file. I split the resulting www object's text property into a string array. I used those strings as keys in a dictionary. When I try to access values of the dictionary with the same strings typed out, a keynotfoundexception occurs. I printed the strings from the string array used to fill the dictionary and the strings used to access the dictionary to the console and they look the same, but their hash codes are not the same. How can I get the dictionary to accept a string with matching characters as the key even though it's hash code is different for some reason?
EDIT: Here is an example of the problem:
Text file: FirstString SecondString ThirdString
Dictionary<string, string> dict = new Dictionary<string, string>();
string[] strings;
using(WWW temp = new WWW(url)) {
yield return temp;
strings = temp.text.Split('\n');
}
for(int i = 0; i < strings.Length; i++) {
dict.Add(strings[i], "whatever");
}
Then, I try to access the dictionary:
dict["FirstString"]
and it doesn't exist as a key, but printing the keys to the console shows that it is a key.
Your answer
Follow this Question
Related Questions
Is there a way to load images into a WebGL app? 2 Answers
Replace chars in String with a Dictionary and avoid order-sensitive problems 0 Answers
WWW class on WebGL: URL is wrong 1 Answer
How to send large strings from Unity WebGL to javascript browser function 1 Answer
Import/Export of save file string 0 Answers