C# – How to get string after specific string

cregex

How to get string after text "playlist:" ?

var YT= "tag:youtube.com,2008:user:hollywoodlife09:playlist:PLDovhwKa3P88MwGzYxMDMfiAiiEWxAJYj" ;

What I did :

string[] s = YT.Split(':');

But it will give me array i.e s[0],s[1] … and I am searching for something which can give result after specific text.

I want string after "playlist:", I know it may be easy with Regex,but currently I don't have any idea for Regex..

Best Answer

You can use Substring method

var output = inputString.SubString(inputString.LastIndexOf("playlist") + 8);

Or in this case it can be done using Last method via Split:

string output = YT.Split(':').Last();