简体   繁体   English

使用字符串作为分隔符拆分字符串

[英]Split a string using a string as delimiter

Is it possible to split a string using a string as delimiter?是否可以使用字符串作为分隔符来分割字符串? If yes, how?如果是,如何?

Example :例子 :

String myString = "hello_world<;>goodbye<;>foo";
myString.split("<;>");

//returns "hello_world", "goodbye" and "foo"

The example in your question works exactly, however this may be coincidental.您问题中的示例完全有效,但这可能是巧合。 Keep in mind that the String.split(...) method accepts a RegEx parameter, not a String delimiter.请记住, String.split(...)方法接受一个 RegEx 参数,而不是一个字符串分隔符。

Check out the RegEx documentation here: http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html#sum在此处查看 RegEx 文档: http : //docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html#sum

是的,正如您在代码中所做的那样。

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

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