【发布时间】:2011-11-29 13:35:55
【问题描述】:
如何检查特定字符串以查看它是否包含一系列子字符串? 具体是这样的:
public GetByValue(string testString) {
// if testString contains these substrings I want to throw back that string was invalid
// string cannot contain "the " or any part of the words "College" or "University"
...
}
【问题讨论】:
-
取决于您如何看待未来的发展。正则表达式可能是一个好的开始。你有没有尝试过?
-
不确定从哪里开始...我的数据访问层正在使用输入的字符串进行搜索...如果字符串包含“the”或“college”或“大学”——例如:“col”或“uni”——那么返回的行太多,太通用了。至于成长,我只关心这三个字。我在 DAL 中使用 Linq to SQL
标签: c#-4.0