Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 为什么我可以从这个字符串中得到子字符串?_Java_Arrays_String_Split_Indexof - Fatal编程技术网

Java 为什么我可以从这个字符串中得到子字符串?

Java 为什么我可以从这个字符串中得到子字符串?,java,arrays,string,split,indexof,Java,Arrays,String,Split,Indexof,我想从一个字符串中得到姓氏“yessine” page.findElement(By.xpath("xxx")) .getAttribute("innerText"); 这根绳子是KCHAOU YESSINE 所以我只想得到yessine,而不是.indexOf(“”)是-1,也是.indexOf(“”)也是-1,我尝试了很多方法,始终是“”或的位置是-1我尝试将字符串保存在.txt文件中并从中读取,但没有成功,始终得到-1和全名 一些尝试 if (iend < 0) {

我想从一个字符串中得到姓氏“yessine”

page.findElement(By.xpath("xxx")) .getAttribute("innerText"); 
这根绳子是KCHAOU YESSINE

所以我只想得到yessine,而不是
.indexOf(“”)
是-1,也是
.indexOf(“”)
也是-1,我尝试了很多方法,始终是“”或
的位置是-1我尝试将字符串保存在.txt文件中并从中读取,但没有成功,始终得到-1和全名

一些尝试

if (iend < 0) {
            String decodedXML= StringEscapeUtils.unescapeHtml(nomPos);
            System.out.println(decodedXML);
            System.out.println(iend);  //<- -1
            String pre=decodedXML.trim();
            String[] text_arr = pre.split(" ", 2); 
            String A = text_arr[1].toLowerCase();
            String ACaps = A.toUpperCase().charAt(0) + A.substring(1, A.length());
            return ACaps;
结果总是一样的

其他没有&nbps;干得好


我如何才能做到这一点?

您可能需要将实际字符用于非中断空格(\u00a0)。参见@RogerLindsjö
int iend=nomPos.indexOf(“u00a0”);系统输出打印号(iend)仍在继续-1@RogerLindsjö
“\u00A0”
工作起来很有魅力,谢谢
Path path1 = Paths.get("temp\\nom.txt");
            try {
                Files.write(path1, Arrays.asList(text_arr));
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
             String nom = String.join("\n", Files.readAllLines(Paths.get("temp\\nom.txt")));
                String[] text = nom.split(" ", 2); // this will give abc
                System.out.println(nom.substring(nom.lastIndexOf(" ") + 1));

            String A = text[1].toLowerCase();
            String ACaps = A.toUpperCase().charAt(0) + A.substring(1, A.length());
            return ACaps;