Hi YCoCg, welcome to forum. You have tagged Rhino 7, so I assume you are referring to GHPython components. In which case, one can use the ReplaceGHPythonString code posted here (last code block):
ReplaceGHPythonString