本文整理了Java中org.apache.brooklyn.util.text.Strings.replaceAllRegex()
方法的一些代码示例,展示了Strings.replaceAllRegex()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Strings.replaceAllRegex()
方法的具体详情如下:
包路径:org.apache.brooklyn.util.text.Strings
类名称:Strings
方法名:replaceAllRegex
[英]REGEX replacement -- explicit method name for readability, doing same as String#replaceAll(String,String).
[中]REGEX replacement——为了可读性而使用的显式方法名,与String#replaceAll(String,String)相同。
代码示例来源:origin: org.apache.brooklyn/brooklyn-utils-common
/** replaces each sequence of whitespace in the first string with the replacement in the second string */
public static String collapseWhitespace(String x, String whitespaceReplacement) {
if (x==null) return null;
return replaceAllRegex(x, "\\s+", whitespaceReplacement);
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-utils-common
@Nullable
@Override
public String apply(@Nullable String s) {
return s == null ? null : Strings.replaceAllRegex(s, pattern, replacement);
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-utils-common
public void testReplaceAllRegex() {
assertEquals(Strings.replaceAllRegex("xyz", "x", ""), "yz");
assertEquals(Strings.replaceAllRegex("xyz", ".", ""), "");
assertEquals(Strings.replaceAllRegex("http://foo.com/", "/", ""), "http:foo.com");
assertEquals(Strings.replaceAllRegex("http://foo.com/", "http:", "https:"), "https://foo.com/");
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
protected String assertSerializeEqualsAndCanDeserialize(Object val, String expected) throws Exception {
String xml = serializer.toString(val);
assertEquals(Strings.replaceAllRegex(xml, "\\s+", ""), Strings.replaceAllRegex(expected, "\\s+", ""));
Object result = serializer.fromString(xml);
LOG.debug("val="+val+"'; xml="+xml+"; result="+result);
assertEquals(result.getClass(), val.getClass());
return expected;
}
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
@Test(groups="Integration")
public void testPipeMultiline() throws Exception {
String output = execRequiringZeroAndReturningStdout(loc,
BashCommands.pipeTextTo("hello world\n"+"and goodbye\n", "wc")).get();
assertEquals(Strings.replaceAllRegex(output, "\\s+", " ").trim(), "3 4 25");
}
内容来源于网络,如有侵权,请联系作者删除!