【发布时间】:2015-07-14 00:32:48
【问题描述】:
我想在邮件合并中替换 sql 数据库中的值。但我似乎在 Visual Studio 中收到一条错误消息。
值不能为空。 参数名称:替换
当我尝试这个时
Regex.Replace(mergeFieldsXML.InnerXml,"«[^»]*" + wordtoReplace + "[^»]*»", SecurityElement.Escape(mailMergeData[wordtoReplace ]),RegexOptions.IgnoreCase);
我想知道是否可以忽略空值并继续替换?
【问题讨论】:
-
请edit您的问题并将每个单词“it”替换为您正在谈论的具体内容。
-
可能是
mailMergeData[key] == null ? "" : mailMergeData[key]或其他方式来识别key是否存在。 -
我试过了也许 mailMergeData[key] == null ? "" : mailMergeData[key] 并且其中一个键是空值。无论如何我可以继续使用null。
-
其中一个键为空?这意味着
wordtoReplace本身可能为空?在这种情况下,我们需要确切地知道mailMergeData是什么(字典?具有索引属性的自定义类?)。无论如何,这不是你得到的错误的意思,错误意味着mailMergeData[wordToReplace]返回 null,所以 sln 对三元运算符的建议应该有效(尽管我个人更喜欢 null 合并运算符,因为它更简洁:mailMergeData[wordtoReplace] ?? string.Empty)
标签: c# regex asp.net-mvc mailmerge