Java tutorial
//package com.java2s; /* * This file is part of ETime. * * ETime is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ETime is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ETime. If not, see <http://www.gnu.org/licenses/>. */ import android.util.Log; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { private static final String TAG = "ETimeUtils-4321"; private static final String TOTAL_STR = "Total: "; /** * Get the total hrs logged this pay period. * * @param page the raw html of the user's timecard page * @return A double representing the total hours logged this pay period by the user. */ protected static double getTotalsHrs(String page) { double total = 0; try { Pattern pattern = Pattern.compile("(?i)(<div.*?>)(" + TOTAL_STR + ")(.*?)(</div>)"); Matcher matcher = pattern.matcher(page); if (matcher.find()) { String totalStr = matcher.group(3); if (!(totalStr == null || totalStr.trim().length() == 0)) { total = Double.parseDouble(totalStr); } } } catch (Exception e) { Log.w(TAG, e.toString()); } return total; } }