C# 如何让文本框删除以阿拉伯语字符开头的字符串(彼此之间是半个字符),就像它在大写字母和默认语言中的小字符一样?
在文本框自动完成属性中,当我输入“m”这样的字符时,它会删除所有以“m”或“m”开头的字符串,但当我写入字符“أ”(这是阿拉伯语字符)时,它只删除以“أ”开头的字符串,我希望当我键入“أ”或“ا”或“إ”或“آ”时,它会删除所有字符串,这些字符串以任何字符开头,而不仅仅是键入的字符,在C#windows应用程序中,我没有使用ASP.netC# 如何让文本框删除以阿拉伯语字符开头的字符串(彼此之间是半个字符),就像它在大写字母和默认语言中的小字符一样?,c#,.net,autocomplete,character-encoding,C#,.net,Autocomplete,Character Encoding,在文本框自动完成属性中,当我输入“m”这样的字符时,它会删除所有以“m”或“m”开头的字符串,但当我写入字符“أ”(这是阿拉伯语字符)时,它只删除以“أ”开头的字符串,我希望当我键入“أ”或“ا”或“إ”或“آ”时,它会删除所有字符串,这些字符串以任何字符开头,而不仅仅是键入的字符,在C#windows应用程序中,我没有使用ASP.net 有什么建议吗 我很惊讶地看到,无论是文本框控件还是自动完成字符串集合都没有办法指定是什么定义了自动完成机制的字符串相等性。我能想到的获得您想要的行为的唯一方法
有什么建议吗 我很惊讶地看到,无论是文本框控件还是自动完成字符串集合都没有办法指定是什么定义了自动完成机制的字符串相等性。我能想到的获得您想要的行为的唯一方法是创建您自己的自动完成机制 在框架提供功能之前,我曾经多次这样做,这并不困难 只需使用可编辑的组合框而不是文本框,并处理TextChanged事件来创建自动完成 以下是一些未经测试的程序伪代码:
bool textChangedProgramatically = false;
List<string> myStrings; // The list of items that can appear in the auto-complete.
private static myComboBox_TextChanged(object sender, EventArgs args)
{
if (textChangedProgramatically)
return;
string searchText = myComboBox.Text;
// Use appropriate culturally-sensative string StartsWith comparisons
List<string> matchingItems = GetMatchingStrings(searchText, myStrings);
string firstMatch;
if (matchingItems.Length > 0)
firstMatch = matchingItems[0];
else
firstMatch = string.Empty;
myComboBox.Items.Clear;
myComboBox.Items.AddRange(matchingItems);
string fulltext = searchText;
if (firstMatch.Length > fullText.Length)
{
fullText = fullText + firstMatch.Substring(fullText.Length);
textChangeProgramatically = true;
myComboBox.Text = fullText;
myComboBox.SelectionStart = searchText.Length;
myComboBox.SelectionLength = fullText.Length - searchText.Length;
textChangeProgramatically = false;
}
}
bool textchangedprogrammaly=false;
列出mystring;//可显示在“自动完成”对话框中的项目列表。
私有静态myComboBox_TextChanged(对象发送方、事件args args)
{
如果(文本按程序更改)
回来
string searchText=mymbobox.Text;
//使用适当的文化敏感字符串开始进行比较
List matchingItems=GetMatchingStrings(searchText,myStrings);
字符串第一匹配;
如果(matchingItems.Length>0)
firstMatch=匹配项[0];
其他的
firstMatch=string.Empty;
myComboBox.Items.Clear;
myComboBox.Items.AddRange(匹配项);
字符串全文=搜索文本;
if(firstMatch.Length>fullText.Length)
{
fullText=fullText+firstMatch.Substring(fullText.Length);
textchangeprogrammetically=true;
myComboBox.Text=全文;
myComboBox.SelectionStart=searchText.Length;
myComboBox.SelectionLength=fullText.Length-searchText.Length;
text change编程=false;
}
}
诀窍是在GetMatchingString中获得正确的匹配行为。在进行比较之前,您可能希望使用字符串兼容性规范化将阿拉伯字符转换为非表示形式,但是我希望正确的子字符串重载可以为您处理所有这些情况。我很惊讶地看到,无论是文本框控件还是自动完成字符串集合都无法指定自动完成机制的字符串相等定义。我能想到的获得您想要的行为的唯一方法是创建您自己的自动完成机制 在框架提供功能之前,我曾经多次这样做,这并不困难 只需使用可编辑的组合框而不是文本框,并处理TextChanged事件来创建自动完成 以下是一些未经测试的程序伪代码:
bool textChangedProgramatically = false;
List<string> myStrings; // The list of items that can appear in the auto-complete.
private static myComboBox_TextChanged(object sender, EventArgs args)
{
if (textChangedProgramatically)
return;
string searchText = myComboBox.Text;
// Use appropriate culturally-sensative string StartsWith comparisons
List<string> matchingItems = GetMatchingStrings(searchText, myStrings);
string firstMatch;
if (matchingItems.Length > 0)
firstMatch = matchingItems[0];
else
firstMatch = string.Empty;
myComboBox.Items.Clear;
myComboBox.Items.AddRange(matchingItems);
string fulltext = searchText;
if (firstMatch.Length > fullText.Length)
{
fullText = fullText + firstMatch.Substring(fullText.Length);
textChangeProgramatically = true;
myComboBox.Text = fullText;
myComboBox.SelectionStart = searchText.Length;
myComboBox.SelectionLength = fullText.Length - searchText.Length;
textChangeProgramatically = false;
}
}
bool textchangedprogrammaly=false;
列出mystring;//可显示在“自动完成”对话框中的项目列表。
私有静态myComboBox_TextChanged(对象发送方、事件args args)
{
如果(文本按程序更改)
回来
string searchText=mymbobox.Text;
//使用适当的文化敏感字符串开始进行比较
List matchingItems=GetMatchingStrings(searchText,myStrings);
字符串第一匹配;
如果(matchingItems.Length>0)
firstMatch=匹配项[0];
其他的
firstMatch=string.Empty;
myComboBox.Items.Clear;
myComboBox.Items.AddRange(匹配项);
字符串全文=搜索文本;
if(firstMatch.Length>fullText.Length)
{
fullText=fullText+firstMatch.Substring(fullText.Length);
textchangeprogrammetically=true;
myComboBox.Text=全文;
myComboBox.SelectionStart=searchText.Length;
myComboBox.SelectionLength=fullText.Length-searchText.Length;
text change编程=false;
}
}
诀窍是在GetMatchingString中获得正确的匹配行为。在进行比较之前,您可能希望使用字符串兼容性规范化将阿拉伯字符转换为非表示形式,但我希望正确的子字符串重载可以为您处理所有这些情况。我非常需要它,有什么帮助吗?我非常需要它,有什么帮助吗??