If you want to select int type values from a given text,
than use the following code
public String SelectINT ( String Text )
{
String point , INT = "" ;
int len = Text.length();
int a = 1;
for(int i=0;i<=(len-1);i++)
{
point = Text.substring(i,a);
try{
int find = Integer.parseInt(point);
if(find==(find+0)){
INT = INT + find;
}
} catch(Exception Number){ }
a = a+1;
}
return INT;
}
Example run:
String getINT1 = SelectINT("abc1d23ef");
int getINT2=Integer.parseInt(getINT1);
so the above code will return "123" which later can be converted to int type using parseInt.
than use the following code
public String SelectINT ( String Text )
{
String point , INT = "" ;
int len = Text.length();
int a = 1;
for(int i=0;i<=(len-1);i++)
{
point = Text.substring(i,a);
try{
int find = Integer.parseInt(point);
if(find==(find+0)){
INT = INT + find;
}
} catch(Exception Number){ }
a = a+1;
}
return INT;
}
Example run:
String getINT1 = SelectINT("abc1d23ef");
int getINT2=Integer.parseInt(getINT1);
so the above code will return "123" which later can be converted to int type using parseInt.
Leave a Reply
Make sure you tick the "Notify Me" box below the comment form to be notified of follow up comments and replies.