Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / September 2007

Tip: Looking for answers? Try searching our database.

Regular Expression Issue

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Nightcrawler - 11 Sep 2007 22:14 GMT
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
Jesse Houwing - 12 Sep 2007 15:36 GMT
Hello Nightcrawler,

> I have a file that contains multiple rows of this kind of data (I have
> only included two rows)..
[quoted text clipped - 20 lines]
>
> 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

--
Jesse Houwing
jesse.houwing at sogeti.nl
Arnshea - 12 Sep 2007 16:35 GMT
> I have a file that contains multiple rows of this kind of data (I have
> only included two rows)..
[quoted text clipped - 22 lines]
>
> 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].

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.