Java字符串占位符(commons-text)替换(转载)
Java字符串占位符(commons-text)替换
https://blog.csdn.net/varyall/article/details/83651798
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.6</version>
</dependency>
@Test
public void test4() {
String param1 = String.format("hi,%s, your age is %s", "john", "26");
System.out.println("-------------------param1=" + param1);
Object[] object = new Object[]{"john", Longs.tryParse("24")};
MessageFormat messageFormat = new MessageFormat("{0} now is at the age of {1}");
String param2 = messageFormat.format(object);
System.out.println("-------------------param2=" + param2); Map<String, String> replaceValue = Maps.newHashMap();
replaceValue.put("name", "john");
replaceValue.put("age", "27");
StrSubstitutor strSubstitutor = new StrSubstitutor(replaceValue);
String template1 = "${name} is at the age of${age}";
String param3 = strSubstitutor.replace(template1);
System.out.println("-------------------param3=" + param3);
}
-------------------param1=hi,john, your age is 26
-------------------param2=john now is at the age of 24
-------------------param3=john is at the age of27
Java字符串占位符(commons-text)替换(转载)的更多相关文章
- Java{0}占位符替换字符串
Java{0}占位符替换字符串 public class Test { public static void main(String[] args) { System.out.println(Stri ...
- es6 模板字变量和字符串占位符
开发者一直在寻找一种创建多行字符串的形式,但要使用单引号双引号字符串一定要在同一行才行. 老办法: 还有其他办法,虽然能实现,但是太啰嗦 es6模板自变量 使用反撇好(`)替换了单双引号 反撇好中的所 ...
- 占位符(placeholder text)
占位符(placeholder text)是用户在input(输入)框输入任何东西之前放置在input(输入)框中的预定义文本. 你可以用如下方式创建占位符: <input type=" ...
- Java使用占位符拼接字符串
大家知道,在C#编程中,可以用占位符来拼接字符串,用起来非常的方便. 特别是需要进行大量的参数拼接的时候,比如: Console.WriteLine(String.Format("该域名{0 ...
- java的占位符
java占位符的类型: 常规类型的格式化 String类的format()方法用于创建格式化的字符串以及连接多个字符串对象.熟悉C语言的同学应该记得C语言的sprintf()方法,两者有类似之处.fo ...
- Java使用占位符拼接字符串-String.format()的使用
String domain = "www.ykmaiz.com"; int iVisit = 0; String info = String.format("该域名%s被 ...
- JAVA字符串格式化-String.format()的使用 (转载)
常规类型的格式化 String类的format()方法用于创建格式化的字符串以及连接多个字符串对象.熟悉C语言的同学应该记得C语言的sprintf()方法,两者有类似之处.format()方法有两种重 ...
- python 字符串占位符的使用
name2='我是{} 我的专业是 {}'.format('张三','计算机科学技术')print(name2)
- 【占位符替换】替换String中的占位符标志位{placeholder}
概述 占位符替换, 占位符表示为:{placeholder}; 示例:替换如下{xxx}占位符中的内容 "名字:{name},年龄:{age},学校:{school}" 提供了两种 ...
随机推荐
- javascript History对象属性和方法
History对象 History对象包含用户(在浏览器窗口中)访问过的URL length: 返回浏览器历史列表中的URL数量(打开浏览器,访问淘宝,返回1,再访问百度,返回2) History对象 ...
- 【2019北京集训测试赛(十三)】数据(sj) 冷静分析
题目大意:给你一个代表区间$[1,n]$的线段树,问你随机访问区间$[1,n]$中的一个子区间,覆盖到的线段树节点个数的期望(需要乘上$\frac{n(n-1)}{2}$后输出). 数据范围:$n≤1 ...
- 你(可能)不知道的web api
你(可能)不知道的web api 简介 作为前端er,我们的工作与web是分不开的,随着HTML5的日益壮大,浏览器自带的webapi也随着增多.本篇文章主要选取了几个有趣且有用的webapi进行介绍 ...
- (转)mtr命令详解诊断网络路由
原文:https://blog.51cto.com/6226001001/1941355 http://www.zzbiji.com/2212.html----Linux下使用mtr做路由图进行网络分 ...
- asp.net core的docker实践
如果centos中没有安装和docker和.net core镜像,先安装docker和asp.net core 镜像 安装dockeryum -y install docker-io 启动 Docke ...
- CentOS 安装 kafka
首先确保JDK已正确安装并设置好环境变量 安装Zookeeper 到官网下载: https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/ zooke ...
- aliyun阿里云Maven仓库配置
maven仓库用过的人都知道,国内有多么的悲催.还好有比较好用的镜像可以使用,尽快记录下来.速度提升100倍. http://maven.aliyun.com/nexus/#view-reposito ...
- 采用完成端口(IOCP)实现高性能网络服务器(Windows c++版)
前言 TCP\IP已成为业界通讯标准.现在越来越多的程序需要联网.网络系统分为服务端和客户端,也就是c\s模式(client \ server).client一般有一个或少数几个连接:server则需 ...
- CSS 基础:定位元素(3)<思维导图>
这段时间利用一下间隙时间学习了CSS的基础知识,主要目的是加深对CSS的理解,虽然个人主要工作基本都是后台开发,但是个人觉得系统学习一下CSS的基础还是很有必要的.下面我学习CSS时做的思维导图(全屏 ...
- leetcode — zigzag-conversion
/** * Source : https://oj.leetcode.com/problems/zigzag-conversion/ * * Created by lverpeng on 2017/6 ...