作者:嘉sen | 来源:互联网 | 2024-10-19 10:12
本文整理了Java中org.apache.commons.text.WordUtils.initials()
方法的一些代码示例,展示了WordUtils.initials()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WordUtils.initials()
方法的具体详情如下:
包路径:org.apache.commons.text.WordUtils
类名称:WordUtils
方法名:initials
WordUtils.initials介绍
暂无
代码示例
代码示例来源:origin: jphp-group/jphp
@Signature
public PTextWord initials(Environment env, @Optional(type = HintType.STRING) String delimiters) {
return new PTextWord(env, WordUtils.initials(text, delimiters.isEmpty() ? null : delimiters.toCharArray()));
}
代码示例来源:origin: org.apache.commons/commons-text
@Test
public void testInitials_String() {
assertThat(WordUtils.initials(null)).isNull();
assertThat(WordUtils.initials("")).isEqualTo("");
assertThat(WordUtils.initials(" ")).isEqualTo("");
assertThat(WordUtils.initials("I")).isEqualTo("I");
assertThat(WordUtils.initials("i")).isEqualTo("i");
assertThat(WordUtils.initials("Ben John Lee")).isEqualTo("BJL");
assertThat(WordUtils.initials(" Ben \n John\tLee\t")).isEqualTo("BJL");
assertThat(WordUtils.initials("Ben J.Lee")).isEqualTo("BJ");
assertThat(WordUtils.initials(" Ben John . Lee")).isEqualTo("BJ.L");
assertThat(WordUtils.initials("i am here 123")).isEqualTo("iah1");
}
代码示例来源:origin: org.apache.commons/commons-text
@Test
public void testInitialsSurrogatePairs() {
// Tests with space as default delimiter
assertThat(WordUtils.initials("\uD800\uDF00\uD800\uDF01 \uD800\uDF02\uD800\uDF03"))
.isEqualTo("\uD800\uDF00\uD800\uDF02");
assertThat(WordUtils.initials("\uD800\uDF00\uD800\uDF01 \uD800\uDF02\uD800\uDF03", null))
.isEqualTo("\uD800\uDF00\uD800\uDF02");
assertThat(WordUtils.initials("\uD800\uDF00 \uD800\uDF02 ", null)).isEqualTo("\uD800\uDF00\uD800\uDF02");
// Tests with UTF-16 as delimiters
assertThat(WordUtils.initials("\uD800\uDF00\uD800\uDF01.\uD800\uDF02\uD800\uDF03", new char[] {'.'}))
.isEqualTo("\uD800\uDF00\uD800\uDF02");
assertThat(WordUtils.initials("\uD800\uDF00\uD800\uDF01A\uD800\uDF02\uD800\uDF03", new char[] {'A'}))
.isEqualTo("\uD800\uDF00\uD800\uDF02");
// Tests with UTF-32 as delimiters
assertThat(WordUtils.initials(
"\uD800\uDF00\uD800\uDF01\uD800\uDF14\uD800\uDF02\uD800\uDF03", new char[] {'\uD800', '\uDF14'}))
.isEqualTo("\uD800\uDF00\uD800\uDF02");
assertThat(WordUtils.initials("\uD800\uDF00\uD800\uDF01\uD800\uDF14\uD800\uDF18\uD800\uDF02\uD800\uDF03",
new char[] {'\uD800', '\uDF14', '\uD800', '\uDF18'}))
.isEqualTo("\uD800\uDF00\uD800\uDF02");
}
代码示例来源:origin: org.apache.commons/commons-text
@Test
public void testInitials_String_charArray() {
char[] array = null;
assertThat(WordUtils.initials(null, array)).isNull();
assertThat(WordUtils.initials("", array)).isEqualTo("");
assertThat(WordUtils.initials(" ", array)).isEqualTo("");
assertThat(WordUtils.initials("I", array)).isEqualTo("I");
assertThat(WordUtils.initials("i", array)).isEqualTo("i");
assertThat(WordUtils.initials("SJC", array)).isEqualTo("S");
assertThat(WordUtils.initials("Ben John Lee", array)).isEqualTo("BJL");
assertThat(WordUtils.initials(" Ben \n John\tLee\t", array)).isEqualTo("BJL");
assertThat(WordUtils.initials("Ben J.Lee", array)).isEqualTo("BJ");
assertThat(WordUtils.initials(" Ben John . Lee", array)).isEqualTo("BJ.L");
assertThat(WordUtils.initials("Kay O'Murphy", array)).isEqualTo("KO");
assertThat(WordUtils.initials("i am here 123", array)).isEqualTo("iah1");
assertThat(WordUtils.initials(null, array)).isNull();
assertThat(WordUtils.initials("", array)).isEqualTo("");
assertThat(WordUtils.initials(" ", array)).isEqualTo("");
assertThat(WordUtils.initials("I", array)).isEqualTo("");
assertThat(WordUtils.initials("i", array)).isEqualTo("");
assertThat(WordUtils.initials("SJC", array)).isEqualTo("");
assertThat(WordUtils.initials("Ben John Lee", array)).isEqualTo("");
assertThat(WordUtils.initials(" Ben \n John\tLee\t", array)).isEqualTo("");
assertThat(WordUtils.initials("Ben J.Lee", array)).isEqualTo("");
assertThat(WordUtils.initials(" Ben John . Lee", array)).isEqualTo("");
assertThat(WordUtils.initials("Kay O'Murphy", array)).isEqualTo("");
assertThat(WordUtils.initials("i am here 123", array)).isEqualTo("");
assertThat(WordUtils.initials(null, array)).isNull();