'Produce a new string based of the format string self with args `args` and return a new string, possibly
symbolic.'

def replace(self, startpos, args):

    argpos = startpos
    string = None
    for component in self.components:
        if isinstance(component, str):
            string = self._add_to_string(string, self.parser.state.se.BVV(component))
        elif isinstance(component, claripy.ast.BV):
            string = self._add_to_string(string, component)
        else:
            fmt_spec = component
            if (fmt_spec.spec_type == 's'):
                str_ptr = args(argpos)
                string = self._add_to_string(string, self._get_str_at(str_ptr))
            else:
                i_val = args(argpos)
                c_val = int(self.parser.state.se.any_int(i_val))
                c_val &= ((1 << (fmt_spec.size * 8)) - 1)
                if (fmt_spec.signed and (c_val & (1 << ((fmt_spec.size * 8) - 1)))):
                    c_val -= (1 << (fmt_spec.size * 8))
                if (fmt_spec.spec_type == 'd'):
                    s_val = str(c_val)
                elif (fmt_spec.spec_type == 'u'):
                    s_val = str(c_val)
                elif (fmt_spec.spec_type == 'c'):
                    s_val = chr((c_val & 255))
                elif (fmt_spec.spec_type == 'x'):
                    s_val = hex(c_val)[2:].rstrip('L')
                elif (fmt_spec.spec_type == 'o'):
                    s_val = oct(c_val)[1:].rstrip('L')
                elif (fmt_spec.spec_type == 'p'):
                    s_val = hex(c_val).rstrip('L')
                else:
                    raise SimProcedureError(("Unimplemented    format    specifier    '%s'" % fmt_spec.spec_type))
                string = self._add_to_string(string, self.parser.state.se.BVV(s_val))
            argpos += 1
    return string
