Java tutorial
//package com.java2s; //License from project: Apache License public class Main { public static int retiraId(String nome) { int id = -1; String idTemp = ""; for (int i = 0; i < nome.length(); i++) { if (nome.charAt(i) == '-') { break; } idTemp += nome.charAt(i); } id = Integer.parseInt(idTemp); return id; } }