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.
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
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
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>