我正在尝试拆分一个字符串:“ @ WWP2- @ POLUXDATAWWP3-TTTTTW @ K826”以提取@ WWP2- @ POLUXDATAWWP3-TTTTTW和826个字符串
执行代码段时:

String expression = "@WWP2-@POLUXDATAWWP3-TTTTTW@K826";
        StringTokenizer tokenizer = new StringTokenizer(expression, "@K");
            if (tokenizer.countTokens() > 0) {
                while (tokenizer.hasMoreTokens()) {
                    System.out.println(tokenizer.nextToken());
                }
            }


同时期望结果是

WWP2-POLUXDATAWWP3-TTTTTW
826

我越来越:

WWP2-
POLUXDATAWWP3-TTTTTW
826

关于如何获取确切的两个字符串的任何想法吗?

最佳答案

    String[] str = expression.split("@K");
    System.out.println(Arrays.toString(str));


试试String#split(“ @ K”);

输出:

[@WWP2-@POLUXDATAWWP3-TTTTTW, 826]

10-07 23:02