Search code examples
c#phpasp.netreplacestrtr

Conversion of strtr php function in C#


Need to convert this php code in C#

strtr($input, '+/', '-_')

Does an equivalent C# function exist?


Solution

  • The PHP method strtr() is translate method and not string replace method. If you want to do the same in C# then use following:

    As per your comments

    string input = "baab";
    var output = input.Replace("a", "0").Replace("b","1");
    

    Note : There is no exactly similar method like strtr() in C#.

    You can find more about String.Replace method here