Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Help me this code! Someone please explain strings!

  1. #1
    Junior Member
    Join Date
    Oct 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help me this code! Someone please explain strings!

    The code
    ------------------------------------------------
    function IsNumber(str)  // (Your explanationHere)
    {
       var arrayChars = "0123456789";  // (Your explanationHere)
       var number=true;     // (Your explanationHere)
       var char;     // (Your explanationHere)
     
       for (i = 0; i < str.length && number == true; i++)    // (Your explanationHere)
       { 
          char = str.charAt(i);    // (Your explanationHere)
          if (arrayChars.indexOf(char) == -1)    // (Your explanationHere)
          {
             number = false;  // (Your explanationHere)
          }
       }
     
       return number;   // (Your explanationHere)
    }
    function length(m1,m2,m3)   // (Your explanationHere)
    {
        var result = m1+""+m2+""+m3;   // (Your explanationHere) 
        return result.length;   // (Your explanationHere)
    }
    -------------------------------------------------


    Please replay me fast thanks you all for having your time
    Last edited by helloworld922; October 17th, 2009 at 11:49 AM.


  2. #2
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: Help me this code! Someone please explain strings!

    This looks like JavaSCRIPT to me. What kind of explanation would you like for all this? What each row does?

    And why do you need this explaining?

    // Json

  3. #3
    Junior Member
    Join Date
    Oct 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help me this code! Someone please explain strings!

    Quote Originally Posted by Json View Post
    This looks like JavaSCRIPT to me. What kind of explanation would you like for all this? What each row does?

    And why do you need this explaining?

    // Json
    Well I need explanation for every row and if you know what it generates of those 0123456789.
    Thanks for any help!

  4. #4
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: Help me this code! Someone please explain strings!

    Basically what happens is you pass a string into the method called IsNumber.

    The method loops through every single character in this string and checks it towards the array of numbers "0123456789".

    If the character is not in that list it will assume that the string you passed into the method is not a number.

    It then returns true or false depending on the result of the loop.

    Something to be cautious of with this method though is that it claims to check for numbers but it would say true for a decimal point number.

    // Json

  5. #5
    Junior Member
    Join Date
    Oct 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help me this code! Someone please explain strings!

    Thanks you!

Similar Threads

  1. Strings
    By BeSwift21 in forum Java Theory & Questions
    Replies: 1
    Last Post: October 13th, 2009, 07:02 PM
  2. can anyone explain this?
    By chronoz13 in forum Java Theory & Questions
    Replies: 4
    Last Post: October 12th, 2009, 02:51 AM
  3. Returning Random Strings from an Array
    By cfmonster in forum Collections and Generics
    Replies: 3
    Last Post: September 8th, 2009, 11:13 PM
  4. Replies: 5
    Last Post: January 30th, 2009, 08:31 PM
  5. Replies: 2
    Last Post: June 19th, 2008, 03:58 AM