如何防止用户在Vb.Net的文本框中输入相同的文本两次? [英] How Do I Prevent A User From Entering A Same Text Twice In A Textbox In Vb.Net?

查看:182
本文介绍了如何防止用户在Vb.Net的文本框中输入相同的文本两次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想解决我遇到的这个问题。基本上我想要的是让用户在文本框中输入某个字符串,然后检查用户输入的字符串是否已由用户输入。如果他在此之前输入它,它将给出一个错误信息(先前已输入输入),否则它会执行应该完成的操作。我被卡住了,我想解决这个问题。任何人都可以建议我一个想法或我可以使用的东西吗?

谢谢

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

推荐答案

例如,你可以保留所有输入的文本 System.Collections.Generic.HashSet< string> 的实例:

https://msdn.microsoft.com/en-us/library/bb359438%28v=vs.110%29.aspx [ ^ ]。



您需要检查字符串是否已经设置,如果不是,请添加一个新字符串。此集合类型提供O(1)的时间复杂度



如果要保留字符串集,可以将其保存在文件并在应用程序启动时恢复。

它可以像纯文本文件一样简单(对于没有行尾字符的字符串)或某些XML,就像这样。



-SA
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


这篇关于如何防止用户在Vb.Net的文本框中输入相同的文本两次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆