Question:What is the difference between substring() and substr()? 

Answer Both substring() and substr() functions are used to extract a fragment of a string but they perform the task in a different way. such as substring() enters the beginning and ending numeric positions of a part of the string to extract, whereas the substr() specifies the position of the first character of the string and number of characters to extract. Example:
1.var str="Bangladesh";
var res=str.substring(6,10);
The result of res will be 'desh'.
2.var st="JavaScript"; 
var res=str.substr(4,6);
The result of res will be 'Script'. 

+ Report
Total Preview: 976
What is the difference between substring() and substr()?
Copyright © 2024. Powered by Intellect Software Ltd