记录代码段中的字符串的位置和长度 (_Syntax_C_StringValue_Pos 0.1版)

记录字符串位置着色效果:

 

 

 

        /// <summary>
        /// 记录代码段中的字符串的位置和长度
        /// </summary>
        /// <param name="sText"></param>
        /// <returns></returns>
        /// 创建时间: 2022-09-03      最后一次修改时间:2022-09-03
        public static DList_<Pair_<int,int>> _Syntax_C_StringValue_Pos(this string sText)
        {
            //string s = "\"\n\"";

            //注释用空格代替
            string sReplace = sText._Syntax_C_Replace_ExplanatoryNote();

            DList_<Pair_<int, int>> dResult = new DList_<Pair_<int, int>>();            
             

            int nPos = sReplace.IndexOf("\"", 0);

            while(nPos != -1)
            {
                if (nPos - 1 >= 0 && nPos - 1 < sText.Length)  //看看双引号前面一个字符是不是 \,如果是则不是字符串标记
                {
                    if (sReplace[nPos - 1] != '\\')
                    {
                        int nLeft = nPos;
                        int nRight = sReplace.IndexOf("\"", nPos + 1);  //找下一个标记

                        while (nRight != -1)
                        {
                            if (nRight - 1 >= 0 && nRight - 1 < sText.Length)  //看看双引号前面一个字符是不是 \,如果是则不是字符串标记
                            {
                                if (sReplace[nRight - 1] != '\\')
                                {

                                    int nEnd = sReplace.IndexOf("\n", nPos + 1);

                                    if (nRight < nEnd) //下一个标记在同一行内
                                    {
                                        dResult.Add(new Pair_<int, int>(nLeft, nRight - nPos + 1));

                                        nPos = nRight;
                                        break;
                                    }                      
                                }
                            }
                            else
                            {
                                return dResult;
                            }

                            nRight = sReplace.IndexOf("\"", nRight + 1);  //找下一个标记
                        }           
                    }
                }
                nPos = sReplace.IndexOf("\"", nPos + 1);
            }

            return dResult;
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值