blah blah blah is here! blah blah » Close

up0down
link

inputPath = @"\\machinename\\newfolderName\\targetfolderName";
how to get expected output as shown below :
output : targetfolderName
Thanks.

last answered 9 months ago

1 answers

up0down
link

this is done easily by splitting the string to get the folder name.
string []folders=inputPath.Split('\\',StringSplitOptions.RemoveEmptyEntries);
to get the last folder do this:
string lastFolder=folders[folders.Length-1];

up0down
link

and conanlive'., why do yu' use the verbatim string literal & adding a escape sequence for backslash...!??
just a singe backslash will do in verbatim..., right..!??

up0down
link

ya since you are adding @ before the string there is no need to write \\ since the escape character won't be effective in the string so you can remove the @ or replace \\ with a single \. In both ways the code written above will work.

up0down
link

hy3 muster., one second'.,
but iF we are using' verbatim & also a \\ inside'.,
then for ex.,
if yu'r <b>opening</b> the file in string inputpath as mentioned above., it'll be a error.., throwing, address cannot be found.,
right..!??

This post was imported from csharpfriends, if you have a similiar question please ask it again.

All previous members have been migrated, hope you enjoy the new platform!

Feedback