![](/img/trans.png)
[英]How do I match part of a string only if it is not preceded by certain characters?
[英]how do I to the auto-completion of combobox match any part of string not only start of string?
假設我有一些物品:
PHP Hypertext Processor
PHP_FOO PHP framework
C# .NET framework
Obama american
Bill gates american
我正在尋找一種方法,以確保在組合框項目的任何部分中在comobobox搜索中輸入的所有文本,不僅是在字符串的開頭,還可以將其設置為自動完成建議。
例如:
輸入的文本: Processor
或PHP
或Hypertext
匹配: PHP Hypertext Processor
文本輸入的PHP Hypertext Processor
文本: american
匹配: Obama
和Bill gates
等。
匹配項應在組合框中定義為建議。
更新我當前的代碼:
private void comboBox1_TextChanged(object sender, EventArgs e)
{
int i = 0;
foreach(object item in comboBox1.Items)
{
string val = (string)item;
string[] words = val.Split(' ');
foreach (string word in words)
{
if (word == comboBox1.Text)
{
////the difficult now it is as set the val variable value in combobox suggestions box?
}
}
i++;
}
}
我該怎么做? 我希望這很清楚。 提前致謝。
您的循環也應該更改..如果您知道它將包含文本,請對初學者使用類似這樣的內容。
foreach (string text in combobox1.Items.Cast<string>())
{
//do stuff with the text
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.