【二郎助手】新增自动补全以大写字母开头的变量

我是在DiyFunction.cs类中新增加了一个变量集合variableDic,变量因为要实时提取,所以没有同自定义关键词的集合wordDic放在一起,各自搞一个集合,好管理。

代码:

public class DiyFunction
    {
        public static Dictionary<string, string> variableDic = new Dictionary<string, string>();

然后在TextChanged事件中提取变量(正则提取)

代码:

void rtb_TextChanged(object sender, EventArgs e)
{
	DiyFunction.variableDic.Clear();//清空变量集合
        rex = new Regex("(\\b[A-Z])[a-zA-Z]*");
        mc = rex.Matches(tSql.Text);
        foreach (Match m in mc)
        {
             if (!DiyFunction.variableDic.ContainsKey(m.Value))
             {
                   DiyFunction.variableDic.Add(m.Value, m.Value);
             }
             int startIndex = m.Index;
             int StopIndex = m.Length;
             tSql.Select(startIndex, StopIndex);

             tSql.SelectionColor = Color.DarkGoldenrod;
             //tSql.SelectionFont = new Font(tSql.SelectionFont, FontStyle.Bold);
                    
                    
       }
}

最后在KeyDown事件中匹配就可以了

//从变量集合中取词和输入词进行匹配
                foreach (KeyValuePair<string, string> str in DiyFunction.variableDic)
                {
                    if (str.Key.Length >= keyValue.Length)
                    {
                        if (str.Key.Substring(0, keyValue.Length).ToLower() == keyValue)
                        {
                            //lb.Items.Add(new KeyValuePair<string, string>(str.Key, str.Value.w2));
                            if (!string.IsNullOrEmpty(str.Value))
                            {
                                list.Add(new KeyValuePair<string, string>(str.Key.Replace("\\", ""), str.Value.Replace("\\[", "[").Replace("\\]", "]").Replace("\\r\\n", "\r\n").Replace("\\n", "\n")));

                                if (str.Key.Length > lbsize)
                                {
                                    lbsize = str.Key.Length;
                                }
                            }
                        }
                    }
                }





评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值