[英]How to trim the last characters from a arrays in Java
I have an Array of 10 strings:我有一个由 10 个字符串组成的数组:
so now when i get the InnerText from the object,所以现在当我从对象中获取 InnerText 时,
i want to trim off the last characters of all the strings within the Array我想修剪掉数组中所有字符串的最后一个字符
I want to get rid of the PDF (3 characters so the pDF at the end is removed) Also - Video (8 characters removed)我想删除 PDF(3 个字符,因此删除了末尾的 PDF)还有 - 视频(删除了 8 个字符)
def Array = []
WebUI.comment('Top of Page - For loop for all Text of pdf and videos, and also clicking on all PDFs')
for (i = 1; i < 10; i++) {
WebUI.delay(1)
WebUI.scrollToPosition(80, 80)
String innertext = driver.findElement(By.xpath(('//div[@class=\'content-sections\']/div[1]//div[@class=\'col-12 col-xl-6\']/div[' +
i) + ']//div[@class=\'item\']')).getText()
println(innertext)
Array << innertext
I have tried:我试过了:
def Arraysliced =Array.size
for (int i = 0;i<Array.size;i++){
Arraysliced[i].substring(0)
println(Arraysliced);
}
String delims = "[ ]+";
String Arraysliced = Array.split(delims)
Arraysliced = Array
def Arraysliced = []
Arraysliced = Array.split('-'[0])
(Array.split('-')[0])
println(Arraysliced)
Can you try below code-你可以试试下面的代码 -
String [] arrsplit = innertext.split("//PDF");
and use arrsplit[0] to add in your code并使用 arrsplit[0] 添加您的代码
> **Output would be**- if innertext is- Create New UserPDFVideo
> arrsplit[0]=Create New User arrsplit[1]=Video //which you need to ignore.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.