如何在函数中的变量内传递一个包含撇号的字符串?

时间:2022-03-25 07:12:17

I'm fetching the inner text of an object from the screen and then I'm equating it with sometime.

我从屏幕上获取一个对象的内部文本,然后我将它等同于某个时间。

String StrInnerText = Driver.findElement(By.xpath("").getText()
String strtext = '"+StrInnerText+"'

But, when this StrInnerText equates something like "30's" or "I'm", my value becomes something like

但是,当这个StrInnerText等同于“30's”或“我是”之类的东西时,我的价值变得像

String strText = '30's' or 'I'm'

which throws an error. How do I handle this?

这会引发错误。我该如何处理?

1 个解决方案

#1


1  

To pass value within a string you need to use

要在字符串中传递值,您需要使用它

String strtext = "Part of your String"+StrInnerText+"rest of the part of your string";

If you want double quotes as well along with your string you need to use

如果你想要双引号以及你需要使用的字符串

String strtext = "\""+StrInnerText+"\"";

#1


1  

To pass value within a string you need to use

要在字符串中传递值,您需要使用它

String strtext = "Part of your String"+StrInnerText+"rest of the part of your string";

If you want double quotes as well along with your string you need to use

如果你想要双引号以及你需要使用的字符串

String strtext = "\""+StrInnerText+"\"";