本文整理了Java中org.apache.commons.lang3.StringUtils.substringBefore()
方法的一些代码示例,展示了StringUtils.substringBefore()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StringUtils.substringBefore()
方法的具体详情如下:
包路径:org.apache.commons.lang3.StringUtils
类名称:StringUtils
方法名:substringBefore
[英]Gets the substring before the first occurrence of a separator. The separator is not returned.
A null string input will return null. An empty ("") string input will return the empty string. A null separator will return the input string.
If nothing is found, the string input is returned.
StringUtils.substringBefore(null, *) = null
StringUtils.substringBefore("", *) = ""
StringUtils.substringBefore("abc", "a") = ""
StringUtils.substringBefore("abcba", "b") = "a"
StringUtils.substringBefore("abc", "c") = "ab"
StringUtils.substringBefore("abc", "d") = "abc"
StringUtils.substringBefore("abc", "") = ""
StringUtils.substringBefore("abc", null) = "abc"
[中]获取第一次出现分隔符之前的子字符串。未返回分隔符。
空字符串输入将返回空值。空(“”)字符串输入将返回空字符串。空分隔符将返回输入字符串。
如果未找到任何内容,则返回字符串输入。
StringUtils.substringBefore(null, *) = null
StringUtils.substringBefore("", *) = ""
StringUtils.substringBefore("abc", "a") = ""
StringUtils.substringBefore("abcba", "b") = "a"
StringUtils.substringBefore("abc", "c") = "ab"
StringUtils.substringBefore("abc", "d") = "abc"
StringUtils.substringBefore("abc", "") = ""
StringUtils.substringBefore("abc", null) = "abc"
代码示例来源:origin: xtuhcy/gecco
@Override
public void setUrl(String url) {
this.url = StringUtils.substringBefore(url, "#");
}
代码示例来源:origin: joelittlejohn/jsonschema2pojo
protected URI removeFragment(URI id) {
return URI.create(substringBefore(id.toString(), "#"));
}
代码示例来源:origin: languagetool-org/languagetool
private static List<byte[]> getLines(BufferedReader br) throws IOException {
List<byte[]> lines = new ArrayList<>();
String line;
while ((line = br.readLine()) != null) {
if (!line.startsWith("#")) {
lines.add(StringUtils.substringBefore(line,"#").trim().getBytes(UTF_8));
}
}
return lines;
}
代码示例来源:origin: jamesdbloom/mockserver
public static String returnPath(String path) {
String result = "";
if (URLParser.isFullUrl(path)) {
result = path.replaceAll(schemeHostAndPortRegex, "");
} else {
result = path;
}
return StringUtils.substringBefore(result, "?");
}
}
代码示例来源:origin: Activiti/Activiti
public Optional<ActionDefinition> find(String implementation){
Optional<ActionDefinition> actionDefinitionOptional = Optional.empty();
String connectorId = StringUtils.substringBefore(implementation,
".");
String actionId = StringUtils.substringAfter(implementation,
".");
List<ConnectorDefinition> resultingConnectors = connectorDefinitions.stream().filter(c -> c.getId().equals(connectorId)).collect(Collectors.toList());
if (resultingConnectors != null && resultingConnectors.size() != 0) {
if (resultingConnectors.size() != 1) {
throw new RuntimeException("Mismatch connector id mapping: " + connectorId);
}
ConnectorDefinition connectorDefinition = resultingConnectors.get(0);
ActionDefinition actionDefinition = connectorDefinition.getActions().get(actionId);
if (actionDefinition == null) {
throw new RuntimeException("Mismatch action id mapping: " + actionId);
}
actionDefinitionOptional = Optional.ofNullable(actionDefinition);
}
return actionDefinitionOptional;
}
}
代码示例来源:origin: languagetool-org/languagetool
private static List<String> loadWordsFromPath(String filePath) throws IOException {
List<String> result = new ArrayList<>();
if (!JLanguageTool.getDataBroker().resourceExists(filePath)) {
return result;
}
try (InputStream inputStream = JLanguageTool.getDataBroker().getFromResourceDirAsStream(filePath);
Scanner scanner = new Scanner(inputStream, "utf-8")) {
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
if (line.isEmpty() || line.startsWith("#")) {
continue;
}
if (line.trim().length() < line.length()) {
throw new RuntimeException("No leading or trailing space expected in " + filePath + ": '" + line + "'");
}
result.add(StringUtils.substringBefore(line, "#"));
}
}
return result;
}
代码示例来源:origin: xtuhcy/gecco
imageDir.mkdirs();
String fileName = StringUtils.substringBefore(imgUrl, "?");
fileName = StringUtils.substringAfterLast(fileName, "/");
File imageFile = new File(imageDir, fileName);
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testSubstringBefore_StringString() {
assertEquals("foo", StringUtils.substringBefore("fooXXbarXXbaz", "XX"));
assertNull(StringUtils.substringBefore(null, null));
assertNull(StringUtils.substringBefore(null, ""));
assertNull(StringUtils.substringBefore(null, "XX"));
assertEquals("", StringUtils.substringBefore("", null));
assertEquals("", StringUtils.substringBefore("", ""));
assertEquals("", StringUtils.substringBefore("", "XX"));
assertEquals("foo", StringUtils.substringBefore("foo", null));
assertEquals("foo", StringUtils.substringBefore("foo", "b"));
assertEquals("f", StringUtils.substringBefore("foot", "o"));
assertEquals("", StringUtils.substringBefore("abc", "a"));
assertEquals("a", StringUtils.substringBefore("abcba", "b"));
assertEquals("ab", StringUtils.substringBefore("abc", "c"));
assertEquals("", StringUtils.substringBefore("abc", ""));
}
代码示例来源:origin: jamesdbloom/mockserver
public static void addSubjectAlternativeName(String host) {
if (host != null) {
String hostWithoutPort = StringUtils.substringBefore(host, ":");
if (!ConfigurationProperties.containsSslSubjectAlternativeName(hostWithoutPort)) {
try {
// resolve host name for subject alternative name in case host name is ip address
for (InetAddress addr : InetAddress.getAllByName(hostWithoutPort)) {
ConfigurationProperties.addSslSubjectAlternativeNameIps(addr.getHostAddress());
ConfigurationProperties.addSslSubjectAlternativeNameDomains(addr.getHostName());
ConfigurationProperties.addSslSubjectAlternativeNameDomains(addr.getCanonicalHostName());
}
} catch (UnknownHostException uhe) {
ConfigurationProperties.addSslSubjectAlternativeNameDomains(hostWithoutPort);
}
}
}
}
代码示例来源:origin: apache/hbase
if (sb.length() > 0) {
for (String columnName : sb.toString().trim().split(" ")) {
String family = StringUtils.substringBefore(columnName, ":");
String qualifier = StringUtils.substringAfter(columnName, ":");
代码示例来源:origin: joelittlejohn/jsonschema2pojo
String pathExcludingFragment = substringBefore(path, "#");
String fragment = substringAfter(path, "#");
URI fragmentURI;
if (selfReferenceWithoutParentFile(parent, path) || substringBefore(stringId, "#").isEmpty()) {
JsonNode parentContent = parent.getParent().getContent();
Schema schema = new Schema(id, fragmentResolver.resolve(parentContent, path, refFragmentPathDelimiters), parent.getParent());
代码示例来源:origin: xtuhcy/gecco
String before = StringUtils.substringBefore(imgUrl, "?");
String last = StringUtils.substringAfter(imgUrl, "?");
String fileName = StringUtils.substringAfterLast(before, "/");
代码示例来源:origin: joelittlejohn/jsonschema2pojo
String fqn = substringBefore(node.get("existingJavaType").asText(), "<");
代码示例来源:origin: Teradata/kylo
/**
* Parse the category name from a full feed name (category.feed)
*/
public static String category(String name) {
return StringUtils.trim(StringUtils.substringBefore(name, "."));
}
代码示例来源:origin: didi/DDMQ
public static String getPackageName(String code) {
String packageName =
StringUtils.substringBefore(StringUtils.substringAfter(code, "package "), ";").trim();
return packageName;
}
代码示例来源:origin: spring-projects/spring-roo
/**
* Extracts the property defined in source. If any property is found returns null.
* @param property
* @return Pair of property metadata and property name
*/
public Pair<Stack<FieldMetadata>, String> extractValidField(String source,
List<FieldMetadata> fields) {
if (source == null) {
return null;
}
source = StringUtils.substringBefore(source, "By");
return currentPartTreeInstance.extractValidProperty(source, fields);
}
代码示例来源:origin: com.atlassian.plugins.rest/atlassian-rest-common
private static String getSanitisedReferrer(final ContainerRequest request) {
return StringUtils.substringBefore(request.getHeaderValue("Referer"), "?");
}
代码示例来源:origin: com.atlassian.plugins.rest/atlassian-rest-common
static Indexes parse(String indexes) {
if (StringUtils.isBlank(indexes)) {
return ALL;
} else if (INDEX_PATTERN.matcher(indexes).matches()) {
return new SimpleIndexes(Integer.parseInt(indexes));
} else if (RANGE_PATTERN.matcher(indexes).matches()) {
final String leftAsString = StringUtils.substringBefore(indexes, ":");
final String rightAsString = StringUtils.substringAfter(indexes, ":");
return new RangeIndexes(
StringUtils.isNotBlank(leftAsString) ? Integer.parseInt(leftAsString) : null,
StringUtils.isNotBlank(rightAsString) ? Integer.parseInt(rightAsString) : null);
} else {
return EMPTY;
}
}
代码示例来源:origin: com.atlassian.plugins.rest/atlassian-rest-common
void logXsrfFailureButNotBeingEnforced(ContainerRequest request, Logger logger) {
final String key = request.getPath();
if (key != null && XSRF_NOT_ENFORCED_RESOURCE_CACHE.getIfPresent(key) == null) {
logger.warn(
"XSRF failure not being enforced for request: {} , origin: {} , referrer: {}, " +
"method: {}",
StringUtils.substringBefore(request.getRequestUri().toString(), "?"),
request.getHeaderValue(CorsHeaders.ORIGIN.value()),
getSanitisedReferrer(request),
request.getMethod()
);
XSRF_NOT_ENFORCED_RESOURCE_CACHE.put(key, Boolean.TRUE);
}
}
代码示例来源:origin: com.atlassian.plugins.rest/atlassian-rest-common
private static void appendParam(Map<String, ExpandInformation> parameters, String expand) {
final ExpandKey key = ExpandKey.from(StringUtils.substringBefore(expand, DOT));
String newParameter = StringUtils.substringAfter(expand, DOT);
DefaultExpandParameter existingParameter = null;
if (parameters.containsKey(key.getName())) {
existingParameter = parameters.get(key.getName()).getExpandParameter();
} else {
existingParameter = new DefaultExpandParameter();
parameters.put(key.getName(), new ExpandInformation(key.getIndexes(), existingParameter));
}
if (StringUtils.isNotBlank(newParameter)) {
appendParam(existingParameter.parameters, newParameter);
}
}
内容来源于网络,如有侵权,请联系作者删除!