Here you can find the source of getInteger(String parameter)
Parameter | Description |
---|---|
parameter | Text to extract the integer. |
public static int getInteger(String parameter)
//package com.java2s; /**//from www .j a v a2 s . c om * Copyright (c) 2006, 2009 Hugo Corbucci and others.<br> * All rights reserved. This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html<br> * <br> * Contributors:<br> * Cristiane M. Sato - initial API and implementation<br> * Julien Renaut, Mariana V. Bravo, Luiz C. Real, Jonas K. Hirata - later contributions<br> * <br> * This file was created on 2006/04/03, 10:44:46, by Cristiane M. Sato.<br> * It is part of package br.org.archimedes on the br.org.archimedes.core project.<br> */ import java.util.Locale; import java.util.Scanner; public class Main { /** * Get the integer value from a string. * * @param parameter * Text to extract the integer. * @return The integer value from the string. */ public static int getInteger(String parameter) { String withDots = withDot(parameter); Scanner stringScanner = new Scanner(withDots); stringScanner.useLocale(Locale.US); return stringScanner.nextInt(); } /** * Replaces commas by dots in the decimal representation. * * @param stringWithComma * The string to modify. * @return Returns the new string. */ private static String withDot(String stringWithComma) { String returnValue; if (stringWithComma == null) { returnValue = null; } else { returnValue = stringWithComma.replace(',', '.'); } return returnValue; } }