isolate text within a string?

  • Thread starter Thread starter Rich P
  • Start date Start date
R

Rich P

I am using the WebRequestMethods.Ftp.ListDirectoryDetails method to get
details of an mp4 file. This returns the following string in the
following format:

"08-24-09 11:21PM 6154794 CIMG2550.mp4"

I want to isolate "CIMG2550.mp4". There will be several listings, and
the one thing each string will have in common is that there is one space
between the file size number and the filename. What is the easiest way
to isolate the text to the right of this space (which would be the
filename and extension)? How to do this? Linq maybe? or is there
something simpler for this case?

If it is linq - what would the linq statement be for this?

Thanks



Rich
 
Rich P said:
I am using the WebRequestMethods.Ftp.ListDirectoryDetails method to get
details of an mp4 file. This returns the following string in the
following format:

"08-24-09 11:21PM 6154794 CIMG2550.mp4"

I want to isolate "CIMG2550.mp4". There will be several listings, and
the one thing each string will have in common is that there is one space
between the file size number and the filename. What is the easiest way
to isolate the text to the right of this space (which would be the
filename and extension)? How to do this? Linq maybe? or is there
something simpler for this case?

If it is linq - what would the linq statement be for this?

Forget about Linq. The way to go is Regular Expressions:

http://msdn.microsoft.com/en-us/library/twcw2f1c.aspx
 
I am using the WebRequestMethods.Ftp.ListDirectoryDetails method to
get details of an mp4 file. This returns the following string in the
following format:

"08-24-09 11:21PM 6154794 CIMG2550.mp4"

I want to isolate "CIMG2550.mp4". There will be several listings, and
the one thing each string will have in common is that there is one
space between the file size number and the filename. What is the
easiest way to isolate the text to the right of this space (which
would be the filename and extension)? How to do this? Linq maybe?
or is there something simpler for this case?

I would split the string on a space and then grab the last element:

string[] split = file.Split(SPACE_CHAR_ARRAY);
int itemToGet = split.Length = 1;

string fileName = split[itemToGet];

Not best naming above, but it shows how to get the file name. Now, this
assumes no space in the file name. If there is a space, you can regex
out the date/time from the rest and then grab everything after the first
space, removing any quote characters, if they can exist.

In this instance, I think using LINQ would be like running around with a
hammer looking for nails.

Peace and Grace,


--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

My vacation and childhood cancer awareness site:
http://www.crazycancertour.com

*******************************************
| Think outside the box! |
*******************************************
 
Thanks all for your replies. The filename will never contain any
spaces, so it likes like the Split method is the way to go. Thanks
again.

Rich
 
Back
Top