UrlQuerySanitizer
一个很方便用来处理url链接的工具类,之前开发过程中遇到需要处理支付宝网页url,获取里面post参数,当时使用String的各种接口进行处理,如果用UrlQuerySanitizer的话就简单多了。比如现在有个Url=http://example.com/?name=Mark,我们使用UrlQuerySanitizer拿到name的值:
Simple example:
UrlQuerySanitizer sanitizer = new UrlQuerySanitizer();sanitizer.setAllowUnregisteredParamaters(true);sanitizer.parseUrl("http://example.com/?name=Joe+User"); String name = sanitizer.getValue("name")); // name now contains "Joe_User" Register ValueSanitizers to customize the way individual parameters are sanitized:
UrlQuerySanitizer sanitizer = new UrlQuerySanitizer();sanitizer.registerParamater("name", UrlQuerySanitizer.createSpaceLegal());sanitizer.parseUrl("http://example.com/?name=Joe+User");String name = sanitizer.getValue("name")); // name now contains "Joe User". (The string is first decoded, which // converts the '+' to a ' '. Then the string is sanitized, which // converts the ' ' to an '_'. (The ' ' is converted because the default unregistered parameter sanitizer does not allow any special characters, and ' ' is a special character.)
PhoneNumberUtils
public static String formatNumber (String phoneNumber, String defaultCountryIso)
PhoneNumverUtils提供了一系列方法用来格式化电话号码
String num = "031185203009";PhoneNumberUtils util = new PhoneNumberUtils();String numFormated = util.formatNumber(num,"CN");
numFormated = 0311-8520-3009
Breaks the given number down and formats it according to the rules for the country the number is from.
Parameters
source The phone number to format
Returns
A locally acceptable formatting of the input, or the raw input if formatting rules aren't known for the number