本文整理了Java中org.apache.commons.lang3.StringUtils.replaceOnce()
方法的一些代码示例,展示了StringUtils.replaceOnce()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StringUtils.replaceOnce()
方法的具体详情如下:
包路径:org.apache.commons.lang3.StringUtils
类名称:StringUtils
方法名:replaceOnce
[英]Replaces a String with another String inside a larger String, once.
A null reference passed to this method is a no-op.
StringUtils.replaceOnce(null, *, *) = null
StringUtils.replaceOnce("", *, *) = ""
StringUtils.replaceOnce("any", null, *) = "any"
StringUtils.replaceOnce("any", *, null) = "any"
StringUtils.replaceOnce("any", "", *) = "any"
StringUtils.replaceOnce("aba", "a", null) = "aba"
StringUtils.replaceOnce("aba", "a", "") = "ba"
StringUtils.replaceOnce("aba", "a", "z") = "zba"
[中]将一个字符串替换为较大字符串中的另一个字符串,一次。
传递给此方法的null引用是no-op。
StringUtils.replaceOnce(null, *, *) = null
StringUtils.replaceOnce("", *, *) = ""
StringUtils.replaceOnce("any", null, *) = "any"
StringUtils.replaceOnce("any", *, null) = "any"
StringUtils.replaceOnce("any", "", *) = "any"
StringUtils.replaceOnce("aba", "a", null) = "aba"
StringUtils.replaceOnce("aba", "a", "") = "ba"
StringUtils.replaceOnce("aba", "a", "z") = "zba"
代码示例来源:origin: zhegexiaohuozi/SeimiCrawler
public static String info(String pattern,Object... params){
for (Object p:params){
pattern = StringUtils.replaceOnce(pattern, "{}", p.toString());
}
return pattern;
}
代码示例来源:origin: alibaba/jvm-sandbox
private static String[] replaceWithSysPropUserHome(final String[] pathArray) {
if (ArrayUtils.isEmpty(pathArray)) {
return pathArray;
}
final String SYS_PROP_USER_HOME = System.getProperty("user.home");
for (int index = 0; index < pathArray.length; index++) {
if (StringUtils.startsWith(pathArray[index], "~")) {
pathArray[index] = StringUtils.replaceOnce(pathArray[index], "~", SYS_PROP_USER_HOME);
}
}
return pathArray;
}
代码示例来源:origin: org.apache.commons/commons-lang3
String tmp = StringUtils.replaceOnce(duration, " 0 days", StringUtils.EMPTY);
if (tmp.length() != duration.length()) {
duration = tmp;
tmp = StringUtils.replaceOnce(duration, " 0 hours", StringUtils.EMPTY);
if (tmp.length() != duration.length()) {
duration = tmp;
tmp = StringUtils.replaceOnce(duration, " 0 minutes", StringUtils.EMPTY);
duration = tmp;
if (tmp.length() != duration.length()) {
duration = StringUtils.replaceOnce(tmp, " 0 seconds", StringUtils.EMPTY);
String tmp = StringUtils.replaceOnce(duration, " 0 seconds", StringUtils.EMPTY);
if (tmp.length() != duration.length()) {
duration = tmp;
tmp = StringUtils.replaceOnce(duration, " 0 minutes", StringUtils.EMPTY);
if (tmp.length() != duration.length()) {
duration = tmp;
tmp = StringUtils.replaceOnce(duration, " 0 hours", StringUtils.EMPTY);
if (tmp.length() != duration.length()) {
duration = StringUtils.replaceOnce(tmp, " 0 days", StringUtils.EMPTY);
duration = StringUtils.replaceOnce(duration, " 1 seconds", " 1 second");
duration = StringUtils.replaceOnce(duration, " 1 minutes", " 1 minute");
duration = StringUtils.replaceOnce(duration, " 1 hours", " 1 hour");
duration = StringUtils.replaceOnce(duration, " 1 days", " 1 day");
return duration.trim();
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testReplaceOnce_StringStringString() {
assertNull(StringUtils.replaceOnce(null, null, null));
assertNull(StringUtils.replaceOnce(null, null, "any"));
assertNull(StringUtils.replaceOnce(null, "any", null));
assertNull(StringUtils.replaceOnce(null, "any", "any"));
assertEquals("", StringUtils.replaceOnce("", null, null));
assertEquals("", StringUtils.replaceOnce("", null, "any"));
assertEquals("", StringUtils.replaceOnce("", "any", null));
assertEquals("", StringUtils.replaceOnce("", "any", "any"));
assertEquals("FOO", StringUtils.replaceOnce("FOO", "", "any"));
assertEquals("FOO", StringUtils.replaceOnce("FOO", null, "any"));
assertEquals("FOO", StringUtils.replaceOnce("FOO", "F", null));
assertEquals("FOO", StringUtils.replaceOnce("FOO", null, null));
assertEquals("foofoo", StringUtils.replaceOnce("foofoofoo", "foo", ""));
}
代码示例来源:origin: DiUS/java-faker
result = StringUtils.replaceOnce(result, escapedDirective, resolved);
代码示例来源:origin: spring-projects/spring-roo
@Override
public String getBaseUrlControllerForFinder(ClassOrInterfaceTypeDetails controller, String finder) {
String basePath = getBaseUrlForController(controller);
return basePath + StringUtils.replaceOnce(finder, "findBy", "by");
}
代码示例来源:origin: org.fcrepo/fcrepo-http-commons
/**
* Converts internal path segments to their external formats.
* @param path the internal path
* @return the external path
*/
public static String convertToExternalPath(final String path) {
String newPath = replaceOnce(path, "/" + CONTAINER_WEBAC_ACL, "/" + FCR_ACL);
newPath = replaceOnce(newPath, "/" + LDPCV_TIME_MAP, "/" + FCR_VERSIONS);
newPath = replaceOnce(newPath, "/" + FEDORA_DESCRIPTION, "/" + FCR_METADATA);
return newPath;
}
代码示例来源:origin: virjar/vscrawler
@Override
protected String handle(String input, String second, String third) {
return StringUtils.replaceOnce(input, second, third);
}
代码示例来源:origin: info.magnolia/magnolia-rendering
protected String processBeforeInjection(String text, Node content, RenderableDefinition definition) throws RepositoryException {
for (String argument : arguments) {
if (content.hasProperty(argument)) {
text = StringUtils.replaceOnce(text, "${" + argument + "}", content.getProperty(argument).getString());
} else {
log.warn("Cannot replace '{}' since '{}' doesn't have such property.", "${" + argument + "}", content);
}
}
return text;
}
代码示例来源:origin: icclab/cyclops
/**
* Apply time stamp to rule definition
* @return string
*/
private String applyTimeStampToRuleDefinition(String rule, String timeStamp) {
String name = RegexParser.getNameFromRule(rule);
String formatted = String.format("%s (%s)", name, timeStamp);
return StringUtils.replaceOnce(rule, name, formatted);
}
代码示例来源:origin: com.atlassian.mail/atlassian-mail
@Nonnull
public StripResult removeFormatting(String text) {
Matcher matcher = COLOR_PATTERN.matcher(text);
String result = text;
String removed = EMPTY;
while (matcher.matches()) {
String group = matcher.group(1);
removed += group;
result = replaceOnce(result, group, EMPTY);
matcher = COLOR_PATTERN.matcher(result);
}
return new StripResult(result, removed);
}
代码示例来源:origin: org.apache.syncope.core/syncope-core-persistence-jpa
@Transactional(readOnly = true)
@Override
public int count() {
StringBuilder queryString = buildFindAllQuery();
Query query = entityManager().createQuery(StringUtils.replaceOnce(
queryString.toString(), "SELECT e", "SELECT COUNT(e)"));
return ((Number) query.getSingleResult()).intValue();
}
代码示例来源:origin: googleapis/gapic-generator
/** Renders the short name of this type given its pattern. */
public String getNickname() {
if (pattern == null) {
return topLevelAlias.getNickname();
}
String result = StringUtils.replaceOnce(pattern, "%s", topLevelAlias.getNickname());
for (TypeName innerTypeName : innerTypeNames) {
result = StringUtils.replaceOnce(result, "%i", innerTypeName.getNickname());
}
return result;
}
代码示例来源:origin: googleapis/gapic-generator
/** Renders the fully-qualified name of this type given its pattern. */
public String getFullName() {
if (pattern == null) {
return topLevelAlias.getFullName();
}
String result = StringUtils.replaceOnce(pattern, "%s", topLevelAlias.getFullName());
for (TypeName innerTypeName : innerTypeNames) {
result = StringUtils.replaceOnce(result, "%i", innerTypeName.getFullName());
}
return result;
}
代码示例来源:origin: avast/hdfs-shell
private String getShortCwd() {
String currentDir = contextCommands.getCurrentDir();
if (currentDir.startsWith("/user/")) {
final String userHome = "/user/" + this.getWhoami();//call getWhoami later
if (currentDir.startsWith(userHome)) {
currentDir = StringUtils.replaceOnce(currentDir, userHome, "~");
}
}
return currentDir;
}
}
代码示例来源:origin: mezz/JustEnoughItems
@Override
public String getFormattedModNameForModId(String modId) {
String modNameFormat = Config.getModNameFormat();
if (modNameFormat.isEmpty()) {
return null;
}
String modName = getModNameForModId(modId);
modName = removeChatFormatting(modName); // some crazy mod has formatting in the name
if (modNameFormat.contains(MOD_NAME_FORMAT_CODE)) {
return StringUtils.replaceOnce(modNameFormat, MOD_NAME_FORMAT_CODE, modName);
}
return modNameFormat + modName;
}
代码示例来源:origin: com.atlassian.jira/jira-core
/**
* We get the relative path for this file
* removing the JIRA Home Path
*/
Option<String> getRelativePathOf(final JiraHome jiraHome, final File file)
{
if(file.getAbsolutePath().startsWith(jiraHome.getHomePath()))
{
return Option.some(StringUtils.replaceOnce(file.getAbsolutePath(), jiraHome.getHomePath(), ""));
}
return Option.none();
}
}
代码示例来源:origin: org.fcrepo/fcrepo-http-commons
@Override
protected String doForward(final String path) {
if (path.contains(TX_PREFIX) && !path.contains(txSegment())) {
throw new RepositoryRuntimeException("Path " + path
+ " is not in current transaction " + session.getId());
}
return replaceOnce(path, txSegment(), EMPTY);
}
代码示例来源:origin: iterate-ch/cyberduck
protected Path expand(final Path remote, final String format) {
if(remote.getAbsolute().startsWith(format)) {
return new Path(StringUtils.replaceOnce(remote.getAbsolute(), format, workdir.getAbsolute()),
remote.getType());
}
return remote;
}
}
代码示例来源:origin: googleapis/gapic-generator
/**
* Renders the value given the value pattern, and adds any necessary nicknames to the given type
* table.
*/
public String getValueAndSaveTypeNicknameIn(TypeTable typeTable) {
if (getValuePattern().contains("%s")) {
String nickname = typeTable.getAndSaveNicknameFor(getTypeName());
return StringUtils.replaceOnce(getValuePattern(), "%s", nickname);
} else {
return getValuePattern();
}
}
}
内容来源于网络,如有侵权,请联系作者删除!