Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I wanted to fix this problem that i encountered. Basically what i want is to let a user enter certain string in a textbox and then check if the string entered by the user has been entered before by the user. If he entered it before then it will give an error message like ("Input has been previously entered") else it does what is supposed to be done. I am stuck and i want to fix this part. Can anyone suggest me an idea or something that i can use?
Thanks
Posted
Comments
Sergey Alexandrovich Kryukov 13-May-15 20:22pm    
What have you tried so far?
—SA

1 solution

For example, you can keep all entered texts in the instance of the System.Collections.Generic.HashSet<string>:
https://msdn.microsoft.com/en-us/library/bb359438%28v=vs.110%29.aspx[^].

You need to check of the string is already in set and, if it is not, add a new one. This collection types provides time complexity of O(1).

If you want to persist the set of string, you can save it in file and restore back on application start.
It could be as simple as plain text file (for strings without end-of-line characters) or some XML, something like that.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900