简体   繁体   中英

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

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

Shortest way I know, but requires "using System.Linq":

s.Split('%').Last();

The other answer is of course alright.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM