首页 新闻 会员 周边

C#代码分析

0
[待解决问题]

哪位大佬能帮我分析一下面代码的大概作用吗

private static string MappingString(DataRow dr, string inStr,bool escapeHTML)
{
if (!String.IsNullOrWhiteSpace(inStr)) inStr = inStr.Trim();
string s = inStr;
if (dr != null)
{

        DataColumnCollection cols = dr.Table.Columns;
        Regex regex = new Regex(replacePattern); //"<[(.+)]>";
        //TODO: escape single quote ,or escape HTML codes
        s = regex.Replace(inStr, delegate(System.Text.RegularExpressions.Match match)
        {
            string resullt = String.Empty;
            if (match.Groups.Count > 0)
            {
                string keyName = match.Groups[1].Value;
                if (!String.IsNullOrWhiteSpace(keyName))
                {
                    if (cols.Contains(keyName)){
                        String sValue =  String.Format("{0}", dr[keyName]);
                        if(escapeHTML)
                            sValue = EscapeHTML(sValue);
                        return sValue;
                    }
                    else
                        resullt = match.Value;
                }
            }
            else
                resullt = match.Value;
            return resullt;
        });
    }
    return s;
}
敲代码带的主页 敲代码带 | 初学一级 | 园豆:0
提问于:2019-06-10 17:31

建议改进一下排版,支持 markdown 代码高亮语法

dudu 4年前
< >
分享
所有回答(1)
0

根据dr的字段名,替换 inStr 中对应的占位符
差不多就是模片转内容的意思

pencile | 园豆:845 (小虾三级) | 2019-06-10 21:19
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册