用unicode处理货币符号


下面这段程序检测读入网页所使用的货币符号,如果直接比较给出货币符号,在本地运行可以通过,但是部署到服务器上,特殊的货币符号将是服务器返回错误信息,比如英镑符号或欧元符号,所以这里用unicode编码来解决这个问题,如 \u00A3z而不用英镑符号£



url = new URL(
                    "http://www.bonhams.com/cgi-bin/public.sh/pubweb/publicSite.r?sContinent=EUR&screen=Catalogue&iSaleNo=18897&maxrows=1000");

BufferedReader in = new BufferedReader(new InputStreamReader(
                    url.openStream(), "ISO-8859-1"));

String str;

try {

while ((str = in.readLine()) != null) {

if (str.toLowerCase().contains("estimate: ")||str.toLowerCase().matches("(.+)sold(.+)for(.+)\\d(.*)")){
                    String tempStr = str.replaceAll(
                            "(<[/]?([a-zA-Z0-9 -=\"'&\\?\\._/:])+[/]?>)",
                            "").trim();

    tempStr = new String(tempStr.getBytes(chset),Charset.forName("ISO-8859-1") );
                                      
                       
                            if (tempStr.contains("\u00A3")){ // £
                                System.out.println("British Pound");
                                System.out.println("\u00A3");
                            } else if (tempStr.contains("$") || tempStr.contains("USD")) {
                                System.out.println("US Dollar");
                               System.out.println("$");
                            } else if (tempStr.contains("H")) {
                                System.out.println("Honk Kong Dollar");
                               System.out.println("HK$");
                            } else if (tempStr.contains("\u20AC")||tempStr.contains("EUR")) {
                                System.out.println("Euro");
                                System.out.println("\u20AC"); //
                            } else if (tempStr.contains("C")) {
                                System.out.println("Zurich Franc");
                                System.out.println("CHF");
                            }
                        }

in.close();
        } catch (Exception e) {
            e.printStackTrace();
        }


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值