Regular Expression Issue

N

Nightcrawler

I have a file that contains multiple rows of this kind of data (I have
only included two rows)..

#TIME:12:55
C:\Documents and Settings\james\My Documents\My Music\Folder\Axwell -
I Found U (Remode).mp3
#TIME:12:56
C:\Documents and Settings\james\My Documents\My Music\Folder\Blaze
feat Mr.V - Breathe (Ashley Beedle Remix).mp3

I want to extract the time (12:55 and 12:56) as well as the mp3 file
name (Axwell - I Found U (Remode) and Blaze feat Mr.V - Breathe
(Ashley Beedle Remix)).

So I need help with the following:

1. Extract the time
2. I need a way to strip out the file path which can be different
since everyone has different harddrives and folder structures.
3. Does anyone have any experince with Mac folder structures. Some
people use macs and I am not really sure if Macs write paths the same
as PC's.

Please help!

Many thanks
 
J

Jesse Houwing

Hello Nightcrawler,
I have a file that contains multiple rows of this kind of data (I have
only included two rows)..

#TIME:12:55
C:\Documents and Settings\james\My Documents\My Music\Folder\Axwell -
I Found U (Remode).mp3
#TIME:12:56
C:\Documents and Settings\james\My Documents\My Music\Folder\Blaze
feat Mr.V - Breathe (Ashley Beedle Remix).mp3
I want to extract the time (12:55 and 12:56) as well as the mp3 file
name (Axwell - I Found U (Remode) and Blaze feat Mr.V - Breathe
(Ashley Beedle Remix)).

So I need help with the following:

1. Extract the time
2. I need a way to strip out the file path which can be different
since everyone has different harddrives and folder structures.
3. Does anyone have any experince with Mac folder structures. Some
people use macs and I am not really sure if Macs write paths the same
as PC's.
Please help!

Many thanks

hello Nightcrawler,

Though Regular Expressions would probably do the trick here, I think it's
easier to use the string functions for splitting up the string. Then use
the System.IO.Path class to get the filename, extention and directories if
you should need them.

Apart from being easier, simple string manipulation would also be much faster.
Given the format, the time you need to extract is always between the index
of the first : and the first space of the string. Use string.indexOf to find
these positions, then use string.Substring to extract the time. The path
part comes right after the first space all the way to the end of the line,
use substring again to get them into a seperate string. Feed that to System.IO.Path
and use it's members to extract the details you need.

http://msdn2.microsoft.com/en-us/library/system.io.path.aspx
 
A

Arnshea

I have a file that contains multiple rows of this kind of data (I have
only included two rows)..

#TIME:12:55
C:\Documents and Settings\james\My Documents\My Music\Folder\Axwell -
I Found U (Remode).mp3
#TIME:12:56
C:\Documents and Settings\james\My Documents\My Music\Folder\Blaze
feat Mr.V - Breathe (Ashley Beedle Remix).mp3

I want to extract the time (12:55 and 12:56) as well as the mp3 file
name (Axwell - I Found U (Remode) and Blaze feat Mr.V - Breathe
(Ashley Beedle Remix)).

So I need help with the following:

1. Extract the time
2. I need a way to strip out the file path which can be different
since everyone has different harddrives and folder structures.
3. Does anyone have any experince with Mac folder structures. Some
people use macs and I am not really sure if Macs write paths the same
as PC's.

Please help!

Many thanks

The following should do it:
":(\d{1,2}:\d{1,2}).*\\([^\\]+)$"

(w/o the double quotes). The time should be in match.Groups[1] and
the filename (including extension) in match.Groups[2].
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top