热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

org.apache.commons.text.WordUtils.initials()方法的使用及代码示例

本文整理了Java中org.apache.commons.text.WordUtils.initials()方法的一些代码示例,展示了WordUtils.i

本文整理了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();

推荐阅读
author-avatar
嘉sen
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有