var str = "Hello, How are you? { This string has many same character like curly braces { and closing curly braces } . Normal string can not replace all occurances of the { open curly braces. and close braces } . The funciton solid replace will replace all { open and close } curly braces. Also the count function will count the number of occurances of { and }.";
function solidReplace(p_str,p_find,p_replace)
{
var arr = p_str.split(p_find);
return arr.join(p_replace);
}
function getCount(p_str,p_search)
{
var arr = p_str.split(p_search);
return arr.length-1;
}
var nstr = "Get Count = " + getCount(str,"{") + "<br>";
nstr+= "Replace { with * " + solidReplace(str,"{","*");
$("#s").html( nstr );
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!