[英]Check if string contains a specific value
我有一個IF
語句,我想檢查我的DropDownList
包含特定的string
。 我可以知道如何檢查嗎?
目前,我正在處理以下語句:
if (DropDownList1.Text='%james%')
{
}
謝謝
if (DropDownList1.SelectedItem.Text.Contains("james")
{
//...
}
如果您需要忽略大小寫,可以執行以下操作:
bool contains = DropDownList1.SelectedItem.Text.IndexOf("james", StringComparison.OrdinalIgnoreCase) >= 0;
if (contains)
{
//...
}
嘗試這個,
if (DropDownList1.Items.Contains(new ListItem("james")))
{
// ... code here
}
要么
if (DropDownList1.Items.FindByText("james") != null)
{
// ... code here
}
使用string。包含檢查一個字符串是否包含另一個字符串。
if (myString.Contains("james")}
{
}
Regex RegX = new Regex("james"); // james or any of your regex string
if (RegX.IsMatch(DropDownList1.Text))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.