Search code examples
c#phpasp.netcharacter-trimming

rtrim php equivalent in C#


I would like to know how to accomplish the PHP

query = rtrim($query, '& ');

in C# ASP .NET MVC

I have tried Strings.RTrim("string") but it does not work.

Have also tried query = query.Trim(query, "&"); but it gives me error.

Also msdn provides code for rtrim in visual basic, which does not help.

From looking at the code it seems like its' trimming the whitespace if found after & character.

Anyone know how to replicate the php command? Cheers


Solution

  • The .Trim() method removes whitespaces from both the start and end of the string, so

    "   Hello World   ".Trim() -> "Hello World"
    

    For performing the RTrim() you can use the TrimEnd() method with the String.

    "   Hello World   ".TrimEnd() -> "   Hello World"