Here you can find the source of convertStringToInteger(String s)
Parameter | Description |
---|---|
String | s |
public static Integer convertStringToInteger(String s)
//package com.java2s; //License from project: Open Source License public class Main { /**//from w w w . j ava2s . c o m * Converts a string to Integer. Non-numeric characters are excluded (example: string " # J1001 " converted to Integer 1001). * @param String s * @return Integer */ public static Integer convertStringToInteger(String s) { Integer _integer = null; if (s != null) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < s.length(); i++) { if (Character.isDigit(s.charAt(i))) { sb.append(s.charAt(i)); } } if (sb.length() > 0) { int id = Integer.parseInt(sb.toString()); _integer = new Integer(id); } } return _integer; } }