集册 Java实例教程 从用户代理获取IE版本

从用户代理获取IE版本

欢马劈雪     最近更新时间:2020-01-02 10:19:05

365
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
从用户代理获取IE版本


//package com.nowjava;/** 来自 nowjava**/

import java.util.regex.Matcher;

import java.util.regex.Pattern;


public class Main {

    public static void main(String[] argv) throws Exception {

        String userAgent = "nowjava.com";

        System.out.println(getIeVersion(userAgent));

    }


    public static int getIeVersion(String userAgent) {

        int version = 7;// 来自 n o w j a   v  a . c o m - 时  代  Java

        Pattern p = Pattern.compile("MSIE");

        Matcher matcher = p.matcher(userAgent);

        if (matcher.find()) {

            int start = matcher.start() + 5;

            int end = matcher.end() + 4;

            
展开阅读全文