简体   繁体   English

在某个子字符串处拆分字符串?

[英]Splitting a string at a certain substring?

I am writing the beginning stages of some code which I will expand on in the next few months. 我正在编写一些代码的开始阶段,这些代码将在接下来的几个月中进行扩展。 The part I am working on now just takes a string. 我现在正在处理的部分只需要一个字符串。 I have this down, but I want to split the string at a certain place:"(li)". 我没有这个,但我想在某个位置分割字符串:“(li)”。 So far I have: 到目前为止,我有:

String[] s = n.split("(li)")

But this is not compiling. 但这还没有编译。 The error says: 错误提示:

Error: cannot find symbol
symbol:   method split(java.lang.String)
location: variable s of type java.lang.String[]

This should work 这应该工作

public static void main(String args[]) {
        String n = "mylitx";
        String[] s = n.split("(li)");
        for (String tag : s)
            System.out.println(tag);
    }

will produce the output as 将产生输出为

my
tx

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

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