substring IP address in java

Posted by m2010 on Stack Overflow See other posts from Stack Overflow or by m2010
Published on 2010-05-29T05:02:17Z Indexed on 2010/05/29 5:12 UTC
Read the original article Hit count: 443

Filed under:
|

This program takes string like that 192.168.1.125 and cut every number then converts it to integer, but it returns an error.

import java.lang.String;
import java.lang.Number;
import java.lang.Integer;
class Ip
{
   public static void main ( String [] args )
   {

      int i ;
      i = args[0].indexOf ( '.' );
      do
      {
         if ( i != -1 )
            args[0].substring ( 0, i );
         String str = args[0].substring ( i + 1, args[0].length() );
         String str2 = Integer.parseInt ( str );
         System.out.println ( str2 );
      }
      while ( i != -1 );
   }
}

© Stack Overflow or respective owner

Related posts about java

Related posts about substring