第14 章 : 类库使用案例分析
59 StringBuffer使用
使用StringBuffer追加26个小写字母。逆序输出,并删除前5个字符 StringBuffer允许修改 String不允许修改
StringBuffer buff = new StringBuffer();
for(int i = 'a'; i
import java.util.regex.Matcher;
import java.util.regex.Pattern;
class Demo {
public static void main(String[] args) {
String html = "";
String regex = "\\w+=\"[a-zA-Z0-9,\\+]+\"";
Matcher matcher = Pattern.compile(regex).matcher(html);
while (matcher.find()){
String temp = matcher.group(0);
String[] result = temp.split("=");
System.out.println(result[0] + "\t" + result[1].replaceAll("\"", ""));
/**
* face Arial,Serif
* size +2
* color red
*/
}
}
}
65 国家代码
实现国际化应用 输入国家代号,调用资源文件 3个资源文件
# message.properties
info=默认资源
# message_en_US.properties
info=英文资源
# message_zh_CN.properties
info=中文资源
import java.io.UnsupportedEncodingException;
import java.util.Locale;
import java.util.ResourceBundle;
class MessageUtil {
// 将固定的内容定义为常量
private static final String CHINA = "cn";
private static final String ENGLISH = "en";
private static final String BASENAME = "message";
private static final String KEY = "info";
public static String getMessage(String country) throws UnsupportedEncodingException {
Locale locale = getLocale(country);
if (locale == null) {
return null;
} else {
ResourceBundle bundle = ResourceBundle.getBundle(BASENAME, locale);
return new String(bundle.getString(KEY).getBytes("ISO-8859-1"), "utf-8");
}
}
private static Locale getLocale(String country) {
switch (country) {
case CHINA:
return new Locale("zh", "CN");
case ENGLISH:
return new Locale("en", "US");
default:
return null;
}
}
}
class Demo {
public static void main(String[] args) throws UnsupportedEncodingException {
if (args.length other.score){
return 1;
} else if (this.score
关注
打赏
最近更新
- 深拷贝和浅拷贝的区别(重点)
- 【Vue】走进Vue框架世界
- 【云服务器】项目部署—搭建网站—vue电商后台管理系统
- 【React介绍】 一文带你深入React
- 【React】React组件实例的三大属性之state,props,refs(你学废了吗)
- 【脚手架VueCLI】从零开始,创建一个VUE项目
- 【React】深入理解React组件生命周期----图文详解(含代码)
- 【React】DOM的Diffing算法是什么?以及DOM中key的作用----经典面试题
- 【React】1_使用React脚手架创建项目步骤--------详解(含项目结构说明)
- 【React】2_如何使用react脚手架写一个简单的页面?