如何将变量插入到一段字符串中,并将单引号作为字符串的一部分.
码:
var textMessage = "myText"; //local variable storing text to be injected to string
Run Code Online (Sandbox Code Playgroud)
这是我尝试过但它没有用的:
"//div[contains(@id,'msgError') and contains(text(),'+textMessage+')]" //string where textMessage should be insterted
Run Code Online (Sandbox Code Playgroud)
OUTPUT应该是这样的:
"//div[contains(@id,'msgError') and contains(text(),'myText')]" //Output
Run Code Online (Sandbox Code Playgroud)
您可以像这样使用string.Format:
string.Format("//div[contains(@id,'msgError') and contains(text(),'{0}')]", textMessage)
Run Code Online (Sandbox Code Playgroud)
您可以指定要放入字符串的更多参数.
| 归档时间: |
|
| 查看次数: |
103 次 |
| 最近记录: |