How to remove all String text before equals ('=') sign Java

前端 未结 4 916
自闭症患者
自闭症患者 2021-01-21 07:51

I\'d like to parse a string so I can build an XML document.

I have:

String value = \"path=/Some/Xpath/Here\";

I\'ve parsed it this way

4条回答
  •  臣服心动
    2021-01-21 08:54

    Just do replace before splitting.

    String[] tokens = s.replaceFirst(".*=", "").split("/");
    

    This would give you an empty element at first because it would do splitting on the first forward slash after replacing.

    or

    String[] tokens = s.replaceFirst(".*=/", "").split("/");
    

    But if you remove all the chars upto the = along with the first forward slash will give you the desired output.

提交回复
热议问题