Ejemplo n.º 1
0
        /// <summary>
        /// 查找行
        /// </summary>
        /// <param name="str"></param>
        private void checkLine(string str)
        {
            MatchCollection matches = Regex.Matches(str, pattern);

            ResStr rs;

            for (int i = 0; i < matches.Count; i++)
            {
                string v2 = matches[i].Value;

                if (Regex.IsMatch(v2, pattern2))
                {
                    rs = new ResStr();
                    //Console.WriteLine(v2);
                    string newV = v2.Substring(1, v2.Length - 2);  // 去掉< > " '符号
                    Console.WriteLine(v2 + "@" + newV);
                    if (dic.ContainsKey(v2) == false)
                    {
                        rs.keyStr      = keyStr + keyIndex;
                        rs.oldValueStr = v2;
                        rs.newValueStr = newV;

                        dic[v2] = rs;
                        keyIndex++;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 替换行
        /// </summary>
        /// <param name="str"></param>
        private string ReplaceLine(string str, ref bool bo)
        {
            if (!Regex.IsMatch(str, pattern2))
            {
                return(str);                                // 此行一个中文也没有直接返回
            }
            //const string methodName = "ResUtils.getLanguageData(\"-\")";
            //const string methodName = "<%=CommonUtils.getLanguage(\"-\")%>";
            const string methodName = "CommonUtils.getLanguage(\"-\")";


            //Console.WriteLine("旧行-ReplaceLine:" + str);

            MatchCollection matches = Regex.Matches(str, pattern);

            for (int i = 0; i < matches.Count; i++)
            {
                string v2 = matches[i].Value;
                if (String.IsNullOrEmpty(v2))
                {
                    continue;
                }
                if (Regex.IsMatch(v2, pattern2))
                {
                    ResStr rs = dic[v2];
                    //str = str.Replace(v2, "123");
                    //Console.WriteLine(v2);
                    if (rs == null)
                    {
                        continue;
                    }
                    if (rs.oldValueStr.IndexOf(">") == -1)
                    {
                        //str = str.Replace(rs.oldValueStr, "\""+methodName.Replace("-", rs.keyStr)+ "\"");
                        str = str.Replace(rs.oldValueStr, methodName.Replace("-", rs.keyStr));
                    }
                    else
                    {
                        str = str.Replace(rs.newValueStr, methodName.Replace("-", rs.keyStr));
                    }
                    if (bo == false)
                    {
                        bo = true;
                    }
                }
            }

            //Console.WriteLine("新行-ReplaceLine:" + str);
            return(str);
        }