Results 1 to 4 of 4

Thread: Get String Length with Javascript

  1. #1
    Join Date
    Aug 2009
    Posts
    36

    Get String Length with Javascript

    I am writing JavaScripts and i need to know what strings are and how they work. I have tried to create a code to find the length of a string with str.length() function but gives error. Can any one tell me how to find the length of a string in JavaScripts.

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    Re: Get String Length with Javascript

    Code:
    <script type="text/javascript">
    var myString = "12345678";
    
    var length = mstr.length;
    
    document.write("The string length : " + length);
    
    document.write("<br />The string is this long: " + myString.length);
    
    </script>
    Output :
    Code:
    The string is this long: 8
    The string is this long: 8

  3. #3
    Join Date
    Jan 2009
    Posts
    199

    Re: Get String Length with Javascript

    Javascript string length :

    The following example uses the length property of the String object to find the length of a string:var txt="string";
    document.write(text1.length);

    The code above will result in the following output:6

    The following example uses the toUpperCase() method of the String object to convert a string to uppercase letters:var txt="string";document.write(txt.toUpperCase());

    The code above will result in the following output:string

  4. #4
    Join Date
    Dec 2008
    Posts
    177

    Re: Get String Length with Javascript

    Strings are simply groups of characters, like 'JavaScript', 'string',
    Code:
    <script language="javascript" type="text/javascript">
    
    var len=" length of chracter";
    alert(len.length);
    
    </script>

Similar Threads

  1. Coversion of Cast string as int in Javascript
    By LaMarcus in forum Software Development
    Replies: 5
    Last Post: 14-10-2010, 03:59 AM
  2. Finding php string length
    By afidelino in forum Software Development
    Replies: 5
    Last Post: 26-02-2010, 07:34 PM
  3. Find and Replace in JavaScript String
    By Wilbur in forum Software Development
    Replies: 5
    Last Post: 15-12-2009, 02:23 PM
  4. Trim a String in JavaScript
    By Kingfisher in forum Software Development
    Replies: 3
    Last Post: 21-11-2009, 10:32 AM
  5. Length of a string displayable in C
    By Berlin Baby in forum Software Development
    Replies: 3
    Last Post: 10-01-2009, 07:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,751,806,508.63022 seconds with 16 queries