This article describes the method of js to implement the number of specific characters in a string. Share it for your reference, as follows:
//js statistics number of specific characters contained in the string function getPlaceholderCount(strSource) { //The number of {} or {xxXX} in the string var thisCount = 0; strSource.replace(//{[xX]+/}|/{/}/g, function (m, i) { //m is the found {xx} element, i is the index thisCount++; }); return thisCount; }PS: Here is another very convenient statistical tool for you:
Online word count tool:
http://tools.VeVB.COM/code/zishutongji
For more information about JavaScript related content, please check out the topics of this site: "Summary of JSON operation techniques in JavaScript", "Summary of JavaScript switching effects and techniques", "Summary of JavaScript search algorithm techniques", "Summary of JavaScript animation effects and techniques", "Summary of JavaScript errors and debugging techniques", "Summary of JavaScript data structures and algorithm techniques", "Summary of JavaScript traversal algorithms and techniques" and "Summary of JavaScript mathematical operations usage"
I hope this article will be helpful to everyone's JavaScript programming.