Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by miguleex · Jun 26, 2019 at 12:57 PM · errorhashtablehashautomation

Hashtable problem c#

I have a hashtable with A lot of words , when i introduce the words manually into the hashtable*[hashtable.add(id,"name")]it works perfectly with [hashtable.ContainsValue(InputField)]*, but somehow, when I introduce data in the hastable via automation, like

     int i = 0;
     foreach (string s in LinesDiccionaryD)
     {
         Tabla.Add(i, s.ToLower());
         i++;
     }
     foreach (string s in LinesDiccionaryS)
     {
         Tabla.Add(i, s.ToLower());
         i++;
     }

it just stop working with [hashtable.ContainsValue(InputField)], how can i solve that, sorry for my english , and thx btw, I hope someone can help me

 using System.Collections;
 using System.Collections.Generic;
 using System.IO;
 using System.Linq;
 using UnityEngine;
 using UnityEngine.UI;
 using UnityEditor;
 
 
 public class DiccionaryReader : MonoBehaviour
 {
     private string LastLine;
     private string line;
     public int currentLine = 0;
     public int CurrentLine3;
     public int CurrentLine4;
 
     Hashtable Tabla;
 
     private string[] lines;
     private string[] LinesDiccionaryS;
     public string[] LinesDiccionaryD;
     private string content;
     private string contentDiccionaryS;
     private string contentDiccionaryD;
     private string[] tokens;
     public Text Palabra;
     public Text Conjugacion;
     public Text Tipo;
     public Text Traduccion;
 
     public bool SearchingForWord;
 
     public bool UpdatingDiccionaries;
     public bool UpdatingDiccionaryD;
     public bool UpdatingDiccionaryS;
 
     public InputField SearchWord;
 
     public TextAsset file;
     public TextAsset FileDiccionaryS;
     public TextAsset FileDiccionaryD;
 
     public void Start()
     {
         FileDiccionaryD = Resources.Load("Info/DiccionaryD") as TextAsset;
         FileDiccionaryS = Resources.Load("Info/DiccionaryS") as TextAsset;
         file = Resources.Load("Info/Diccionary") as TextAsset;
 
         content = file.text;
         contentDiccionaryD = FileDiccionaryD.text;
         contentDiccionaryS = FileDiccionaryS.text;
 
         lines = content.Split('\n');
         LinesDiccionaryD = contentDiccionaryD.Split('\n');
         LinesDiccionaryS = contentDiccionaryS.Split('\n');
 
         Tabla = new Hashtable();
         NewWord();
 
         int i = 0;
         foreach (string s in LinesDiccionaryD)
         {
             Tabla.Add(i, s.ToLower());
             i++;
         }
         foreach (string s in LinesDiccionaryS)
         {
             Tabla.Add(i, s.ToLower());
             i++;
         }
         foreach (var key in Tabla.Keys)
         {
             Debug.LogWarningFormat("{0}: {1}", key, Tabla[key]);
         }
     }
 
     public void NewWord()
     {
         {
             var r = new System.Random();
             int randomNumber = r.Next(0, lines.Length);
 
             // Read the random line
             line = lines.Skip(randomNumber - 1).Take(1).First();
 
             string Output = line;
             LastLine = line;
 
             string MainString = Output;
             tokens = MainString.Split('&');
 
             Palabra.text = tokens[0];
             Tipo.text = tokens[1];
             Conjugacion.text = tokens[2];
             Traduccion.text = tokens[3];
         }
     }
 
     public void Update()
     {
         if (Tipo.text == "V")
         {
             Tipo.text = "Verbo";
         }
         else if (Tipo.text == "S")
         {
             Tipo.text = "Sustantivo";
         }
         else if (Tipo.text == "O")
         {
             Tipo.text = "Oracion";
         }
         else if (Tipo.text == "A")
         {
             Tipo.text = "Otro";
         }
     }
 
     public void SearchForWord()
     {
         Debug.Log(Tabla.Count);
         Debug.Log(SearchWord.text);
 
         if (Tabla.ContainsValue("ab"))
         {
             Debug.Log("la encontre");
         }
         else if (Tabla.ContainsKey(SearchWord.text))
         {
             var key = Tabla[SearchWord.text];
             Debug.Log(key);
         }
         else
         {
             Debug.Log("Ni Fruta idea que estas buscando");
         }
     }
 }




Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Zarenityx · Jun 26, 2019 at 08:02 PM 0
Share

I would like to help but I'm afraid I'm a bit unclear about the question...

It is also incredibly difficult to read your question due to the current formatting. I recommend using muti-line code format for stuff like this:

 //Code like this for long snippets

As opposed to using single line code like this.

Also, please only post relevant code and not entire scripts unless absolutely necessary. Finally, don't post an answer to amend your question, but ins$$anonymous$$d edit the question itself or use comments for side-notes.

I fear that in its current state your question will go un-answered. I recommend deleting and re-posting this question, using more readable formatting and providing more details about the actual problem. Stuff like this can go a long way to ensure a question gets answered and not forgotten.

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by Bunny83 · Jun 26, 2019 at 10:23 PM

Your code makes no sense. Your hashtable has integer values as keys. So you can not possibly find a string key in that hashtable. It's not really clear what that hashtable should be used for. A hashtable maps a key to another value. You just used an integer index as key and the actual string as value. If you want to be able to actually find the string values, you should have the string as key. However it's not clear to which value you want to map each word to.


If you just want a hash table to see if a word exists or not you should use a HashSet. The Hashtable class shouldn't really be used anyways. It's generally better to use the generic classes like the HashSet i just mentioned or if you actually need a mapping use a generic Dictionary. If you would have used a generic dictionary your code wouldn't even compile since you have to specify your key and value type. So adding integers but testing for strings can never work.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

140 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Hashtable.Enumerator: snapshot out of sync 1 Answer

Hashtable Bejeweled movement 1 Answer

Causing a chain reaction and hashtable errors 0 Answers

Fast nearest neighbour searches 0 Answers

Converting String to Variable Name 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges