有没有工具类可以截取出指定字符两边的字符串

比如key=value 我要取到key和value不要中间的=号截取出来的可以是一个字符串数组

String array[]="key=value".split("=");

strong text
字符串split("="),放到一个数组里面,然后可以用一个加强for循环for(String str:array)遍历出来就OK了

使用java.util.Properties的load方法可以更好实现。

public void loadProperties() {
    Properties properties = new Properties();
    try {
        String str1 = "language=java",
               str2 = "language=java;charset=utf-8;mode=dev";

        properties.load(new ByteArrayInputStream(str1.getBytes(Charset.defaultCharset())));
        properties.load(
                new ByteArrayInputStream(str2.replace(";", "\n").getBytes(Charset.defaultCharset())));
    } catch (IOException ioe) {
        System.out.println("Load error!");
    }
    System.out.println(properties.get("language"));
    System.out.println(properties.get("charset"));
}