Find a substring, replace a substring according the case
<p>What's the easiest and fastest way to find a sub-string(template) in a string and replace it with something else following the template's letter case (if all lower case - replace with lowercase, if all upper case  - replace with uppercase, if begins with uppercase and so on...)</p>

<p>so if the substring is in curly braces</p>

<pre><code>"{template}" becomes "replaced content"
"{TEMPLATE}" becomes "REPLACED CONTENT" and
"{Template}" becomes "Replaced content" but
"{tEMPLATE}" becomes "rEPLACED CONTENT"
</code></pre>
