November 10th, 2012, 08:08 AM
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
July 14th, 2014, 11:07 PM
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.