Extract only digits from a string
import javax.swing.JOptionPane;
import org.apache.commons.lang3.StringUtils;
public class extract_digits
{
public static void main(String[] args)
{
String sStr=JOptionPane.showInputDialog("Enter any string with Digit");
String sRes="";
int sTemp;
for (int i=1 ; i<=sStr.length();i++)
{
try
{
sTemp=Integer.parseInt(StringUtils.mid(sStr, i, 1));//substring(sStr, 1, end)
sRes=sRes+"\n"+sTemp;
}catch (Exception e)
{
}
}
System.out.println(sRes);
}
}
No comments:
Post a Comment