Search code examples
c#stringtrim

Remove all chars up to last known char C#


I have some string:

var s = "*%hello%my%name%is%Mike%HowAreYou";

The Mike%HowAreYou is changed from object to object.

I want to trim all the start up to the last % and get HowAreYou

How can I do that in the best way? Thanks


Solution

  • s.Substring(s.LastIndexOf('%') + 1)