C#
Class x
{
string Insurer{get;set;}
}
Now,
x.Insurer=txtInsurer.Text;
现在文件strText包含@Insurer替换为x.Insurer
strText = strText.Replace("@Insurer","\""+x.Insuerer+"\"");
strText的输出是
保险人:"",
我的要求是如果txtInsurer.Text为空,则strText文件包含@Insurer replaces with null i.e Insurer:null,
instead of Insurer:"",
答案 0 :(得分:2)
使用三元运算符:
strText = strText.Replace("@Insurer", x.Insuerer == null
? "NULL"
: ("\"" + x.Insuerer + "\""));