asp.net – 可以添加一个String.contains多个值吗?
发布时间:2020-12-16 06:33:58 所属栏目:asp.Net 来源:网络整理
导读:我想创建一个控件,当我创建一个companyId时,不允许使用特殊字符创建id,如(),(/),(),(?),(‘): If txtIdCompany.Text.Contains("") Then // alert error message End If 但我不能这样做: If txtIdCompany.Text.Contains("","/","") Then // alert error me
我想创建一个控件,当我创建一个companyId时,不允许使用特殊字符创建id,如(&),(/),(),(?),(‘):
If txtIdCompany.Text.Contains("&") Then // alert error message End If 但我不能这样做: If txtIdCompany.Text.Contains("&","/","") Then // alert error message End If 如何检查同一行中的多个字符串? 解决方法
您可以使用Char()和Enumerable.Contains之类的集合.由于String实现了IEnumerable(Of Char),即使这种简洁高效的LINQ查询也能工作:
Dim disallowed = "&/" If disallowed.Intersect(txtIdCompany.Text).Any() Then ' alert error message End If 这是使用Enumerable.Contains的类似方法: If txtIdCompany.Text.Any(AddressOf disallowed.Contains) Then ' alert error message End If 使用 If txtIdCompany.Text.IndexOfAny(disallowed.ToCharArray()) >= 0 Then ' alert error message End If (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc-5 – 如何让Glimpse与EF6合作?
- ASP.NET页面在IE缓存的清除办法
- asp.net-mvc – 变化:*错误地添加到http标头响应(asp.net
- asp.net-core – 如何从控制器调用View组件
- Asp.Net MVC 5 Framework(非核心)中的Angular 4服务器端渲染
- asp.net – 如何在一个新的选项卡中打开asp:HyperLink.Nav
- asp.net – 如何绑定一个MemoryStream到asp:图像控件?
- 当会话状态超时在asp.net mvc中完成时,如何重定向到登录页面
- asp.net – 禁用Durandal内联样式
- asp.net-mvc – 什么时候创建ApiController实例?
推荐文章
站长推荐
- asp.net – 强制RadComboBox下拉方向
- asp.net-mvc – ASP.NET MVC:部分知道它是否是从
- ASP.NET版CKEditor与CKFinder的配置使用
- ASP.NET MVC 2 – ViewModel前缀
- 视图页面中的asp.net标识声明全名
- asp.net-mvc-4 – 为什么MVC4捆绑和缩小使我的文
- entity-framework – 此版本的Entity Framework核
- 如何使用asp.net和c#流式传输Excel 2007或Word 2
- asp.net-mvc – 可以通过RedirectToAction传递模
- asp.net – 使用Html.TextBox添加css类
热点阅读