日期:2014-05-19  浏览次数:20830 次

C#字符串格式化问题
1、   script   =   string.Format( "function   SetCommonSimulation{0}(obj){   if   (obj   ==   undefine){eval( 'Textbox{0} ').innerText= 'error '}else{ ",   this._objectAddress);
但在调试的时候出现字符串格式错误,问题是在 "{ "这个字符的问题,在进行格试化字符串时,怎么样使{作为一个普通的字符格式化,而不是让它认为是一个转义的变量?

------解决方案--------------------
一般是在其前面加上 "/ "
------解决方案--------------------
加\转义符就行了!
------解决方案--------------------
字符串前加@
------解决方案--------------------
script = string.Format(@ "function SetCommonSimulation{0}(obj){ if (obj == 'undefine '){eval( 'Textbox{0} ').innerText= 'error '}else{ ", this._objectAddress);

------解决方案--------------------
string script= "function SetCommonSimulation{this._objectAddress}(obj){ if (obj == undefine){eval( 'Textbox{0} ').innerText= 'error '}else{ ";
script=script.Replace( "this._objectAddress ",this._objectAddress);
----
string script= "function SetCommonSimulation{ "+this._objectAddress+ "}(obj){ if (obj == undefine){eval( 'Textbox{0} ').innerText= 'error '}else{ ";
//string.Format对 {}有特殊的含义,我不知道里面是几层,所以不知道怎么转
上面俩喜欢哪个用哪个吧