是否存在任何图书馆APIC或regex型号,以分立一些划定者,并自动地从每个要素引领和跟踪空间,而不必穿透这些要素?
例如,在分批<代码>上,A B # C#D# E#“ on #
上,预期产出为[A、C、D、E]
。
最近的I got是[A、C、D、E]
。
是否存在任何图书馆APIC或regex型号,以分立一些划定者,并自动地从每个要素引领和跟踪空间,而不必穿透这些要素?
例如,在分批<代码>上,A B # C#D# E#“ on #
上,预期产出为[A、C、D、E]
。
最近的I got是[A、C、D、E]
。
坐在你分裂之前
" A B # C#D# E # ".trim().split("\s*#\s*")
<代码>后天线的空间[A、C、D、E]只是<代码>。
Guava到救援! Use CharMatcher和Joiner, only to itching the Iterable Backjoint, clear show that the iterable only has the letter in it, with no pa, extraneousspace, or hash sign.
package main;
import com.google.common.base.CharMatcher;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
public class TestMain {
static Splitter split = Splitter.on(CharMatcher.anyOf(" #")).trimResults()
.omitEmptyStrings();
static Joiner join = Joiner.on(", ");
public static void main(String[] args) {
final String test = " A B # C#D# E # ";
System.out.println(join.join(split.split(test)));
}
}
产出:
A, B, C, D, E
那些从小管处获得头痛的人大。
为什么在分裂之前做一个替代物呢?
str.replaceall("\s*#\s*","#").split()
Edited to correct whitespace error that was pointed out by Marcus.
我认为,适当的规范应当是:
str.split("[\s]*#[\s]*");
http://regexpal.com/“rel=“nofollow”http://regexpal.com/。
否则,它就应当如此:
" A B # C#D# E # "
.split( # )
.map(function(item) { return item.trim(); } )
.filter(function(n){ return n != "" });
outputs: ["A B", "C", "D", "E"]
Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...
Check this, List<String> list = new ArrayList<String>(); for (int i = 0; i < 10000; i++) { String value = (""+UUID.randomUUID().getLeastSignificantBits()).substring(3, ...
I am in the middle of solving a problem where I think it s best suited for a decorator and a state pattern. The high level setting is something like a sandwich maker and dispenser, where I have a set ...
I have been trying to execute a MS SQL Server stored procedure via JDBC today and have been unsuccessful thus far. The stored procedure has 1 input and 1 output parameter. With every combination I ...
I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...
If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...
I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....
I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...