我的项目工作正常,直到我不得不考虑一个字符串数组而不仅仅是一个......我不知道如何解决这个问题.这Country是此方法所在的当前类的属性.它曾经是一个单独的字符串,但现在是一个数组.
最初它看起来像这样:
private Expression<Func<Payment, bool>> CountryMatches()
{
if (Country.Length < 1) return Skip;
return payment => payment.Country.ToLower().Contains(Country.ToLower());
}
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚的是如何设置它,以便如果Country匹配中的任何字符串payment.Country...当然这是传回一个表达式...这是我最好的猜测(但显然不正确)如何做我需要做的事:
private Expression<Func<Payment, bool>> CountryMatches()
{
if (Country.Length < 1) return Skip;
return payment => payment.Country.ToLower() == Country.Any().ToLower();
}
Run Code Online (Sandbox Code Playgroud) 我有这个代码搜索列表并返回标题,如果它匹配搜索词,但目前如果我尝试搜索'测试',它不会返回结果.如在列表中,它是'测试'.
请协助.
try
{
objCurrentWeb = SPContext.Current.Web;
objSSList = objCurrentWeb.Lists["Sales Materials"];
foreach (SPListItem objSSListItem in objSSList.Items)
{
if (Convert.ToString(objSSListItem["Title"]).Contains(searchWord))
{
resultLabel.Text = objSSListItem["Title"].ToString();
}
}
}
catch (Exception ex)
{
resultLabel.Text = ex.Message;
}
Run Code Online (Sandbox Code Playgroud) 我有一个字符串人(键)和字符串地址(值)的字典.我希望有一个if语句,如果我的字典中的任何键包含子字符串'anders',则返回true.有没有办法做到这一点?我已经尝试过dict.ContainsKey("anders"),但如果任何键被明确命名为"anders",则返回true.即使密钥是安德森或安徒生,我也希望它返回真实.我知道这是一个非常奇怪的案例,但我需要它是出于某种目的.
谢谢
我有公司类内的人员名单.
public class Company{
IList<Person> persons;
}
Run Code Online (Sandbox Code Playgroud)
然后我有一个公司列表,
IList<Company> companies;
Run Code Online (Sandbox Code Playgroud)
现在我有一个名字(说"Lasantha").如果这个名字是公司任何人姓名的一部分,我想找到那家公司.我尝试过使用companies.Contains()方法.我在Person类中覆盖了object.Equals方法,如下所示,
public override bool Equals(object o)
{
var other = o as Person;
return this.Name.ToLower().Contains(other.Name.ToLower());
}
Run Code Online (Sandbox Code Playgroud)
但这不起作用.它也没有称这种Equal方法.有谁可以帮助我吗.
谢谢.
到目前为止我所读到的Linq(以及C#)已经进行了区分大小写的检查.
如何使其不敏感?
这是我的代码,它返回0行,我在数据库中有一条记录
bool result = Employee.SearchBy(x => x.Name.Contains("johN schulZ"));
Run Code Online (Sandbox Code Playgroud)
这返回true:
bool result = Employee.SearchBy(x => x.Name.ToLower().Contains("johN schulZ".ToLower()));
Run Code Online (Sandbox Code Playgroud)
后一个解决方案正在运行,但我想知道是否有更方便的方法.
我想检查下面的字符串是否包含c#中的top/TOP/toP/Top/TOp/Top.我的代码就像
string str = null;
str = "CSharp Top11111 10 BOOKS";
if (str.Contains("top") == true)
{
Console.WriteLine("The string Contains() 'TOP' ");
}
else
{
Console.WriteLine("The String does not Contains() 'TOP'");
}
Run Code Online (Sandbox Code Playgroud)
但只有当我的字符串包含'top'时它才会返回true.对于所有其他场景,如何才能返回true?我知道这可能很简单,但我搜索了很多没有找到任何解决方案
我喜欢C#,但是,例如,像下面这样简单的条件对于它想要实现的目标非常冗长:
if ( (ctr == "BT") || (ctr = "B") ) {
ctrName = "Brian";
} else if ( (ctr == "G") || (ctr = "GD") ) {
ctrName = "George";
}
Run Code Online (Sandbox Code Playgroud)
我在想,在理想的语言中,它可以被编码为:
if ctr:
in {"BT", "B"}: ctr = "Brian"
in {"G", "GD" }: ctr = "George"
Run Code Online (Sandbox Code Playgroud)
有没有更像那样的语言?
我从互联网上尝试了几种解决方案,并通过一些教程使自己工作了,但是我无法使其工作。我尝试将字符串中的单词与之前和/或之后的随机字母,数字或点进行匹配。
例如。
会议室
会议厅21
房间
Meeting2Room
会议室
12会议室110.会议室
我尝试匹配“ Room”一词,但不应区分大小写。
我尝试的最后一个模式是:\ b()(\ w Room \ w)\ b \ ig
但是我使用正则表达式的次数不多,三个月后我很难解决问题。
我希望有一个人可以帮助我。
public bool Regex_check_for_match(string input, string pattern)
{
bool ismatch = Regex.IsMatch(input, pattern);
return ismatch;
}
Run Code Online (Sandbox Code Playgroud)