Quantcast
Browsing all 43 articles
Browse latest View live

Answer by Rebecca Chernoff for How to count string occurrence in string?

The g in the regular expression (short for global) says to search the whole string rather than just find the first occurrence. This matches is twice:var temp = "This is a string.";var count =...

View Article


How to count string occurrence in string?

How can I count the number of times a particular string occurs in another string. For example, this is what I am trying to do in Javascript:var temp = "This is a string.";alert(temp.count("is"));...

View Article


Answer by sachin sahu for How to count string occurrence in string?

let str="sachinsahu";let output={};for (var i = 0; i < str.length; i++) { console.log(str[i]); let ch=str[i]; if(!output[ch]){ output[ch]=1; } else{ output[ch]+=1; }}console.log(output);

View Article
Browsing all 43 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>