简体   繁体   English

在包含/的java中拆分字符串

[英]split a string in java containing /

i split the strings below by the last / of the path: 我按路径的最后一个/分割下面的字符串:

html/body/div/div/table/tbody/tr/td/div/table/tbody/tr/td/table/tbody/tr/td/font/table/tbody/tr/td/p = Infoprat
html/body/div/div/table/tbody/tr/td/table/tbody/tr/td/table/tbody/tr/td/a = 547 astuces Windows 95/98
html/body/div/div/table/tbody/tr/td/table/tbody/tr/td/table/tbody/tr/td/p = Infoprat

and i got this result : 我得到了这个结果:

html/body/div/div/table/tbody/tr/td/div/table/tbody/tr/td/table/tbody/tr/td/font/table/tbody/tr/td
html/body/div/div/table/tbody/tr/td/table/tbody/tr/td/table/tbody/tr/td/a = 547 astuces Windows 95
html/body/div/div/table/tbody/tr/td/table/tbody/tr/td/table/tbody/tr/td

but in the second line , because of a the / in 547 astuces Windows 95/98 , it didnt work. 但是在第二行中,由于547中的/在Windows 95/98中,它没有工作。 how can i ignore this / in 547 astuces Windows 95/98 ? 我如何在547 astuces Windows 95/98中忽略此问题?

my code is : 我的代码是:

line = line.substring(0,line.lastIndexOf("/"));

You can split the string with = and then perform the required operations on the first element of the array returned by the split operation. 您可以使用=分割字符串,然后对split操作返回的数组的第一个元素执行所需的操作。

line = line.split("=")[0];
// input: html/body/div/div/table/tbody/tr/td/table/tbody/tr/td/table/tbody/tr/td/a = 547 astuces Windows 95/98
// output: html/body/div/div/table/tbody/tr/td/table/tbody/tr/td/table/tbody/tr/td/a 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM