how to split a string

Posted by Chanti444 under ASP.NET on 10/19/2011 | Points: 10 | Views : 2210 | Status : [Member] | Replies : 3
hi..............

i need how to split a string code ..............

check one below string once

F:\arbortrek\chanti\projecttotalcode\projecttotalcode\gallery\2016/jul/09/11-00/rajesh/cobra/07 Cobra and snake charmer.jpg



here i need only some part from gallery/2016/jul/09/11-00/rajesh/cobra/07 cobra and snake charmer.jpg

can u help me how to remove gallery front part of all

satya


Responses

Posted by: Hmanjarawala on: 10/19/2011 [Member] Bronze | Points: 25

Up
0
Down
var str = @"F:\arbortrek\chanti\projecttotalcode\projecttotalcode\gallery\2016/jul/09/11-00/rajesh/cobra/07 Cobra and snake charmer.jpg"
str = str.SubString(str.IndexOf("gallery"))

Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

Chanti444, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Niladri.biswas on: 10/19/2011 [Member] Platinum | Points: 25

Up
0
Down
Try this

Solution 1:

string pattern = "gallery";

string source = @"F:\arbortrek\chanti\projecttotalcode\projecttotalcode\gallery\2016/jul/09/11-00/rajesh/cobra/07 Cobra and snake charmer.jpg";
var result = Regex.Split(source, pattern)[1];


Solution 2:
string[] stringSeparators = new string[] { "gallery" };

string source = @"F:\arbortrek\chanti\projecttotalcode\projecttotalcode\gallery\2016/jul/09/11-00/rajesh/cobra/07 Cobra and snake charmer.jpg";
var result = source.Split(stringSeparators, StringSplitOptions.None)[1];


Output
\2016/jul/09/11-00/rajesh/cobra/07 Cobra and snake charmer.jpg


Best Regards,
Niladri Biswas

Chanti444, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Chanti444 on: 10/19/2011 [Member] Starter | Points: 25

Up
0
Down
thnq

satya

Chanti444, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response