#1
  1. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Nov 2012
    Posts
    1
    Rep Power
    0

    Count characters between 2 specified words in javascript


    Hi guys,

    I have a text(string): >0000: brown fox <0000


    now i want to count the characters between the words >0000 and <0000. How do i do that? . Obviously the result will be 9(with spaces) or 8(without spaces). i dont mind if its with spaces or without. i prefer it would be without though.

    What is the coding that is needed?

    Any help will be deeply appreciated guys! thanx in advance
  2. #2
  3. No Profile Picture
    Registered User

    Join Date
    Jun 2011
    Location
    Pasig City, Philippines
    Posts
    24
    Rep Power
    0
    Hi!

    You may use the length property to count the number of characters of a string.

    If you don't want the whitespaces to be counted, use the replace property to replace the occurences of space with empty string.

    You need to create a new variable to store your new string with the whitespaces replaced with empty string.

    var string = "brown fox";
    var stringNoSpaces = string.replace(" ","");
    var stringCount = stringNoSpaces.length;
    document.getElementById("sample").innerHTML = stringCount;

    I hope this helps. Thank you.

Similar Threads

  1. Count words
    By D.O.M.I.N.A.T.O.R in forum .NET Development
    Replies: 6
    Last Post: April 26th, 2006, 07:21 AM
  2. count number of characters
    By Gisash1 in forum ASP Development
    Replies: 3
    Last Post: August 12th, 2005, 12:37 PM
  3. Replies: 1
    Last Post: April 1st, 2005, 02:52 PM
  4. Replies: 1
    Last Post: February 16th, 2005, 10:52 AM

IMN logo majestic logo threadwatch logo seochat tools logo