首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何让文本框丢弃以阿拉伯字符(半个)开头的字符串,就像它在默认语言中使用大写字符和小字符一样?

如何让文本框丢弃以阿拉伯字符(半个)开头的字符串,就像它在默认语言中使用大写字符和小字符一样?
EN

Stack Overflow用户
提问于 2011-05-16 09:31:52
回答 1查看 480关注 0票数 2

在文本框自动完成属性中,当我输入一个像'm‘这样的字符时,它会丢弃所有以'm’或'M‘开头的字符串,但当我写一个字符'أ’(这是一个阿拉伯字符)时,它只会丢弃以'أ‘开头的字符串,当我输入'أ’、'ا‘、'إ’或'آ‘时,它会丢弃所有以非键入字符开头的字符串,在windows应用程序中,我没有使用ASP.net任何建议?

EN

回答 1

Stack Overflow用户

发布于 2011-05-17 03:52:37

我非常惊讶地看到,文本框控件和自动完成字符串集合都无法为自动完成机制指定定义字符串相等的内容。我能想到的获得你想要的行为的唯一方法是创建你自己的自动补全机制。

在框架提供功能之前,我已经做过几次了,这并不困难。

只需使用可编辑的ComboBox而不是TextBox,并处理TextChanged事件来创建自动完成。

以下是该过程的一些未尝试过的伪代码:

代码语言:javascript
复制
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;
    }
}

诀窍是在GetMatchingStrings中获得正确的匹配行为。在进行比较之前,您可能希望使用字符串兼容性规范化将阿拉伯字符转换为非表示形式,但我希望正确的SubString重载可以为您处理所有这些情况。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6012469

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档