Go to Top

Sunday, 2 October 2011

Libraries 1 : String length function

Here's a program that mimics the string length function.

Java Program : 

class str
{
 static int len(String s)
 {
     int i,length=0;
     char c;
     for(i=0;;i++)
     {
         try
         {
            c=s.charAt(i);
            length++;
        }
        catch(Exception e)
        {
            break;
            }
        }
     return length;
}
}

Call this class wherever required, syntax will be like this :

Syntax : 

int length=str.len(string_name);

No comments:

Post a Comment

ShareThis