def replace_str(text, old, new, count=-1):
    """
    Creates a copy of ``text`` with all occurrences of substring ``old`` replaced by ``new``. 
    
    If the optional argument ``count`` is given, only the first count occurrences are replaced.
     
    :param text: The string to copy
    :type text:  ``str``
    
    :param old: The old string to replace
    :type old:  ``str``
    
    :param new: The new string to replace with
    :type new:  ``str``
    
    :param count: The number of occurrences to replace
    :type count:  ``int``
    
    :return: A copy of ``text`` with all occurrences of substring ``old`` replaced by ``new``. 
    :rtype:  ``str``
    """
    assert isinstance(text,str), '%s is not a string' % text
    return text.replace(old,new,count)