org.apache.commons.lang3.StringUtils.chop()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(4.8k)|赞(0)|评价(0)|浏览(322)

本文整理了Java中org.apache.commons.lang3.StringUtils.chop()方法的一些代码示例,展示了StringUtils.chop()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StringUtils.chop()方法的具体详情如下:
包路径:org.apache.commons.lang3.StringUtils
类名称:StringUtils
方法名:chop

StringUtils.chop介绍

[英]Remove the last character from a String.

If the String ends in \r\n, then remove both of them.

StringUtils.chop(null)          = null 
StringUtils.chop("")            = "" 
StringUtils.chop("abc \r")      = "abc " 
StringUtils.chop("abc\n")       = "abc" 
StringUtils.chop("abc\r\n")     = "abc" 
StringUtils.chop("abc")         = "ab" 
StringUtils.chop("abc\nabc")    = "abc\nab" 
StringUtils.chop("a")           = "" 
StringUtils.chop("\r")          = "" 
StringUtils.chop("\n")          = "" 
StringUtils.chop("\r\n")        = ""

[中]从字符串中删除最后一个字符。
如果字符串以\r\n结尾,请同时删除它们。

StringUtils.chop(null)          = null 
StringUtils.chop("")            = "" 
StringUtils.chop("abc \r")      = "abc " 
StringUtils.chop("abc\n")       = "abc" 
StringUtils.chop("abc\r\n")     = "abc" 
StringUtils.chop("abc")         = "ab" 
StringUtils.chop("abc\nabc")    = "abc\nab" 
StringUtils.chop("a")           = "" 
StringUtils.chop("\r")          = "" 
StringUtils.chop("\n")          = "" 
StringUtils.chop("\r\n")        = ""

代码示例

代码示例来源:origin: org.apache.commons/commons-lang3

@Test
public void testChop() {
  final String[][] chopCases = {
      {FOO_UNCAP + "\r\n", FOO_UNCAP},
      {FOO_UNCAP + "\n", FOO_UNCAP},
      {FOO_UNCAP + "\r", FOO_UNCAP},
      {FOO_UNCAP + " \r", FOO_UNCAP + " "},
      {"foo", "fo"},
      {"foo\nfoo", "foo\nfo"},
      {"\n", ""},
      {"\r", ""},
      {"\r\n", ""},
      {null, null},
      {"", ""},
      {"a", ""},
  };
  for (final String[] chopCase : chopCases) {
    final String original = chopCase[0];
    final String expectedResult = chopCase[1];
    assertEquals("chop(String) failed",
        expectedResult, StringUtils.chop(original));
  }
}

代码示例来源:origin: apache/metron

@Override
 public Object apply(List<Object> strings) {
  if(strings == null || strings.size() == 0 ) {
   throw new IllegalArgumentException("[CHOP] missing argument: string to be chopped");
  }
  String var = strings.get(0) == null?null: (String) strings.get(0);
  if(var == null) {
   return null;
  }
  else if(var.length() == 0) {
   return var;
  }
  else {
   return StringUtils.chop(var);
  }
 }
}

代码示例来源:origin: apache/phoenix

commandArgs = StringUtils.chop(commandArgs);

代码示例来源:origin: org.jasig.ssp.util.importer/ssp-data-importer-impl

@Override
public void writeHeader(Writer writer) throws IOException {
  StringBuffer header = new StringBuffer();
  if(columnNames == null){
    logger.error("Column names not found");
    throw new IOException("Unable to write table, column names not found");
  }
  for(String columnName:columnNames){
    header.append(columnName).append(delimiter);
  }
  writer.write(StringUtils.chop(header.toString()));
}

代码示例来源:origin: Piwigo/Piwigo-Android

private String getAccountName(String siteUrl, String username) {
  Uri uri = Uri.parse(siteUrl);
  String sitename = uri.getHost() + uri.getPath();
  if (sitename.endsWith("/")) {
    sitename = StringUtils.chop(sitename);
  }
  return resources.getString(R.string.account_name, username, sitename.toLowerCase(Locale.ROOT));
}

代码示例来源:origin: apache/phoenix

for (String oneCmd : cmds) {
 if (StringUtils.endsWith(oneCmd, "\\")) {
  command += StringUtils.chop(oneCmd) + "\\;";
  continue;
 } else {

代码示例来源:origin: skroutz/elasticsearch-analysis-turkishstemmer

/**
 * Checks the last consonant rule of a word.
 *
 * @param   word  the word to check its last consonant
 * @return        the new word affected by the last consonant rule
 */
public String lastConsonant(String word) {
 if(lastConsonantExceptions.contains(word))
  return word;
 int wordLength = word.length();
 char lastChar = word.charAt(wordLength - 1);
 switch(lastChar) {
  case 'b':
   lastChar = 'p';
   break;
  case 'c':
   lastChar = 'ç';
   break;
  case 'd':
   lastChar = 't';
   break;
  case 'ğ':
   lastChar = 'k';
   break;
 }
 return StringUtils.chop(word) + lastChar;
}

代码示例来源:origin: org.xworker/xworker_core

public static String chop(ActionContext actionContext){
  Thing self = actionContext.getObject("self");
  String str  = (String) self.doAction("getStr", actionContext);
  return StringUtils.chop(str);
}

代码示例来源:origin: watson-developer-cloud/java-sdk

/**
 * Gets the mock web server url.
 *
 * @return the server url
 */
protected String getMockWebServerUrl() {
 return StringUtils.chop(server.url("/").toString());
}

代码示例来源:origin: org.ligoj.plugin/plugin-id

final String csvHeaders = StringUtils.chop(ArrayUtils.toString(sanitizeColumns)).substring(1).replace(',', ';')
    + "\n";

代码示例来源:origin: watson-developer-cloud/assistant-with-discovery

ProxyResource proxy = new ProxyResource();
proxy.setCredentials("dummy", "dummy", StringUtils.chop(server.url("/").toString()));

相关文章

微信公众号

最新文章

更多

StringUtils类方法