'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 1:[1]
s.Substring(s.LastIndexOf('%') + 1)
Solution 2:[2]
Shortest way I know, but requires "using System.Linq":
s.Split('%').Last();
The other answer is of course alright.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | steamrolla |
| Solution 2 | Jonas Metzler |
