I have string:
and I will have:
How can I replace anything to null?
I'm bad men.and I will have:
I'm men.How can I replace anything to null?
I'm bad men.I'm men.
<?php
string replace(string in, string token, string replaceWith)
{
return in.Replace(token, replaceWith);
}
?>
<?php
string myString = "I'm bad men.";
myString = replace(myString, " bad", "");
?>
But when working with games, doing it like I showed is much better practice.
Sorry, but wrapping a framework method just for that seems like a really bad idea and at least to me your example doesn't make any sense whatsoever. You're just unnecessarily creating a new method call that needs it's own space in memory plus all the parameters, etc. etc. The only thing you're fixing (badly, I might add) is code that was put there intentionally for illustration purposes. I could've just assigned the result of the replace method back to the withBad variable, but that would've defeated the variable name.
<?php
string myString = "I'm bad men.".Replace(" bad", "");
?>

myString = myString.Replace(" bad", "");