Loading ...

Substring in javascript | CodeAsp.Net

Substring in javascript

 /5
0 (0votes)

In this blog I will explain how to use substring in javascript. To explain that I have used substring method of JavaScript. The substring() method extracts the characters in a string between two specified indices. Its syntax is stringObject.substring(startIndex,stop). Here startIndex is the index in the string from where we want to start the fetching of string and stop is the length in numeric, means number of characters to fetch after the start index from. Below is the code to explain it:

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title></title>

</head>

<body>

</body>

<script type="text/javascript">

var testString = 'This is test string';

var newString = testString.substring(0, 4);

alert(newString);

</script>

</html>

The alert window, will show only “Test” as we have used substring(0,4) which means start from 0 index and then count for characters from it.

Happy Reading !

 

 

Comments (no comments yet)

Top Posts