JSFiddle - React, Tailwind, and code Playground

by Bhaumik Gadani

HTML

<div id="s"></div>

JavaScript

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 );