【发布时间】:2019-03-17 10:15:19
【问题描述】:
在下面的字符串中,我想通过与总字符串分开来将日期保存在单独的变量中。
String text="The client start date is 13/10/2018";
String[] effectiveDateText=text.split(" ");
for(int i=0;i<effectiveDateText.length;i++){
String effectiveDate=effectiveDateText.length-1;
}
我收到一条编译器错误消息
类型不匹配:无法从 int 转换为 String
将日期放入单独变量的正确方法是什么?
【问题讨论】:
-
string singleDate = effectiveDateText[(effectiveDateText.length)-1] 是你需要的。
-
感谢编辑。你的问题现在很清楚,我已经投票支持重新开放。
-
如果这是用于 Selenium 测试,为什么不另辟蹊径呢?如果您想检查日期是否为
13/10/2018,请连接前面的文本并检查您从 Selenium 获得的文本是否匹配。"The client start date is " + expectedDate。或者可以测试text.endsWith("13/10/2018")。 -
Ayush Goel 想说:Selenium 不用于拆分字符串。阅读 Java 或您正在使用的任何编程语言中的字符串操作。