/// <summary> /// id=1&pid=1 转化为 Page_{id}_{pid}.html 形式 /// </summary> /// <param name="ParaStr">参数字符串</param> /// <param name="FormatStr">格式字符串</param> /// <returns></returns> public static string StaticUrl(string ParaStr, string FormatStr) { ParaStr = ("&" + ParaStr + "&").ToLower(); string str = FormatStr.ToLower();//小写 string[,] Arry = RegexTool.GetRegResultArray(str, @"{(.*?)}"); for (int i = 0; i < Arry.GetUpperBound(0); i++) { string d = RegexTool.GetRegValue(ParaStr, @"&" + Arry[i, 1] + "=(.*?)&"); str = str.Replace("{" + Arry[i, 1] + "}", d); } return(str); }
/// <summary> /// 获输入字符串内外层循环标记位置数组 /// </summary> /// <param name="strIn"></param> /// <returns></returns> private static int[,] IndexFlagArry(string strIn) { string[,] IndexArry = RegexTool.GetRegResultArray(strIn, @"(}\$|\$[\w]*{)"); //匹配 ${ 或 $Head{ 或 }$ //string[,] IndexArry = GetRegArry(strIn, @"(}\@|\@[\w\W]*{)");//匹配 ${ 或 $Head{ 或 }$ int beginFlagCount = 0; //开始标记个数 int endFlagCount = 0; //结束标记个数 string beginFlagIndex = ""; //开始标记位置 string endFlagIndex = ""; //结束标记位置 if (IndexArry.GetUpperBound(0) > 0) //包含标记时,把第一个标记作为第一个循环的开始标记 { beginFlagIndex = IndexArry[0, 0]; } List <string> indexs = new List <string>(); for (int i = 0; i < IndexArry.GetUpperBound(0); i++) { //str += i.ToString() + "-" + IndexArry[i, 0] + IndexArry[i, 1] + "\r\n"; if (IndexArry[i, 1].IndexOf("{") != -1) { beginFlagCount++; } if (IndexArry[i, 1].IndexOf("}") != -1) { endFlagCount++; } if (beginFlagCount == endFlagCount) { endFlagIndex = IndexArry[i, 0]; indexs.Add(beginFlagIndex + "-" + endFlagIndex); if (IndexArry.GetUpperBound(0) > i) { beginFlagIndex = IndexArry[i + 1, 0]; } } } int[,] FlagArry = new int[indexs.Count + 1, 2]; for (int i = 0; i < indexs.Count; i++) { string[] tempArry = indexs[i].Split('-'); FlagArry[i, 0] = Convert.ToInt32(tempArry[0]); FlagArry[i, 1] = Convert.ToInt32(tempArry[1]); } return(FlagArry); }