现在的位置: 首页 > 综合 > 正文

简单东西-String的format

2016年01月05日 ⁄ 综合 ⁄ 共 435字 ⁄ 字号 评论关闭

        Java的String类的静态方法format可以完成对字符串的格式化,在web应用中替换请求路径中的参数信息时可以使用

这个简单的函数。

       使用format比我以前用String的replace来替换参数,高明多了。

       简单代码如下:

public class StringTest {
	public static void main(String[] args) {
		String requestPath = "http://localhost:8080/mini_web/user=%s&password=%s";
		requestPath = String.format(requestPath, "wang","****");
		System.out.println("requestPath :"+requestPath);
	}
}

测试结果:

requestPath :http://localhost:8080/mini_web/user=wang&password=****



抱歉!评论已关闭.