2016-07-04 8 views
-4

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:"", 
+5

あなたが正確に何をしたい理解できない結果 –

+0

が良いだろう理解しにくいです – Mark

+0

を例示データを提供し、期待することができれば –

答えて

2

演算子を使用します。

strText = strText.Replace("@Insurer", x.Insuerer == null 
    ? "NULL" 
    : ("\"" + x.Insuerer + "\"")); 
関連する問題