2012-08-27 271 views
0
string res1 = "CalcAPI.GetXElementValue(" + "\"" + res[0] + "\"" + "," + "\"" + res[1] + "\"" + "," + false + ")" 

字符串連接

res[0] = "IRS5555" 
res[1] = "IRS001" 

輸出這個代碼是:

CalcAPI.GetXElementValue("IRS5555","IRS001",False) 

,但我想

CalcAPI.GetXElementValue("IRS5555","IRS001",false) 

false小寫。

對不起,不提供完整的代碼... 假的也不是一成不變的......

public static object GetElementDataType(string DataType) 
    { 
     ///Write here methos for fetching data type of current element. 
      object res = null; 
     switch (DataType.ToLower()) 
      { 
       case "int": 
       res = 0; 
       break; 
       case "double": 
       res = 0.0; 
       break; 
       case "string": 
       res = ""; 
       break; 
       case "myboolean": 
       res = false; 
       break; 
       default: 
       res = ""; 
       break; 
      } 
     return res; 
    } 

    string res1 = 
     "CalcAPI.GetXElementValue(" + "\"" + res[0] + "\"" + "," 
            + "\"" + res[1] + "\"" + "," 
            + GetElementDataType("myboolean") + ")" 

那麼結果是

CalcAPI.GetXElementValue("IRS5555","IRS001",False) 

,但我想

CalcAPI.GetXElementValue("IRS5555","IRS001",false) 

如果我傳雙

string res1 = "CalcAPI.GetXElementValue(" + "\"" + res[0] + "\"" + "," + "\"" + res[1] + "\"" + "," + GetElementDataType("double") + ")" 

那麼結果是

CalcAPI.GetXElementValue("IRS5555","IRS001",0) 

,但我想

CalcAPI.GetXElementValue("IRS5555","IRS001",0.0) 

如果我通過串

string res1 = "CalcAPI.GetXElementValue(" + "\"" + res[0] + "\"" + "," + "\"" + res[1] + "\"" + "," + GetElementDataType("string") + ")" 

那麼結果是

CalcAPI.GetXElementValue("IRS5555","IRS001",) 

但我想

CalcAPI.GetXElementValue("IRS5555","IRS001","") 
+1

怎麼樣'字符串RES1 = 「CalcAPI.GetXElementValue(」 + 「\」 「+ RES [0] + 」\「」 + 「」 +「\ 「」+ res [1] +「\」「+」,false)「'? –

回答

0

使用ToLower將()函數這樣

string res1 = "CalcAPI.GetXElementValue(" + "\"" + res[0] + "\"" + "," + "\"" + res[1] + "\"" + "," + false.ToString().ToLower() + ")" 
1

使用false.ToString().ToLower()

+0

Jensen在ToString的末尾添加括號(); –

+0

糟糕,打字速度太快。 – Jensen

+0

我明白詹森 –

0

嘗試

false.ToString().ToLower() 
5

如果你假是恆定的存在,那麼你可以使用簡單的字符串。而它`最好使用字符串格式:

string res1 = string.Format("CalcAPI.GetXElementValue(\"{0}\",\"{1}\",false)", res[0], res[1]);