473,396 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Regex class

Hi
I have string as path\track.mp3 eg "C:\Mp3\Korn\korn - trash.mp3" and
I want to have only korn - trash.mp3 file without path. How should I
do it?

Jun 7 '07 #1
4 1361
On Jun 7, 1:53 pm, _nabuchodonozor <kkoce...@wsb-nlu.edu.plwrote:
I have string as path\track.mp3 eg "C:\Mp3\Korn\korn - trash.mp3" and
I want to have only korn - trash.mp3 file without path. How should I
do it?
Use Path.GetFilename

Jon

Jun 7 '07 #2
_nabuchodonozor wrote:
I have string as path\track.mp3 eg "C:\Mp3\Korn\korn - trash.mp3" and
I want to have only korn - trash.mp3 file without path. How should I
do it?
string s = @"C:\Mp3\Korn\korn - trash.mp3";
Console.WriteLine(Regex.Match(s, @"[^\\]+$").Value);

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jun 7 '07 #3
On Jun 7, 2:08 pm, Martin Honnen <mahotr...@yahoo.dewrote:
_nabuchodonozor wrote:
I have string as path\track.mp3 eg "C:\Mp3\Korn\korn - trash.mp3" and
I want to have only korn - trash.mp3 file without path. How should I
do it?

string s = @"C:\Mp3\Korn\korn - trash.mp3";
Console.WriteLine(Regex.Match(s, @"[^\\]+$").Value);
That certainly copes with the example given - but it won't cope with
the perfectly valid path "C:/Mp3/Korn/korn - trash.mp3".

Given that .NET provides a class specifically for this purpose (Path)
I think it makes sense to use it :)

Jon

Jun 7 '07 #4
Given that .NET provides a class specifically for this purpose (Path)
I think it makes sense to use it :)

Jon
Use the static class:
System.IO.Path

or use the instance class:
System.IO.FileInfo

Which you pick depends if you will do more operations with it or not.
If youre going to rename the file, or get propeties on it, use FileInfo

Jun 7 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Peter Kleiweg | last post by:
I want to use regular expressions with less typing. Like this: A / 'b.(..)' # test for regex 'b...' in A A # get the last whole match A # get the first group in the...
3
by: Alan Pretre | last post by:
Can anyone help me figure out a regex pattern for the following input example: xxx:a=b,c=d,yyy:e=f,zzz:www:g=h,i=j,l=m I would want four matches from this: 1. xxx a=b,c=d 2. yyy e=f 3....
3
by: Jon Maz | last post by:
Hi All, Am getting frustrated trying to port the following (pretty simple) function to CSharp. The problem is that I'm lousy at Regular Expressions.... //from...
7
by: bill tie | last post by:
I'd appreciate it if you could advise. 1. How do I replace "\" (backslash) with anything? 2. Suppose I want to replace (a) every occurrence of characters "a", "b", "c", "d" with "x", (b)...
20
by: jeevankodali | last post by:
Hi I have an .Net application which processes thousands of Xml nodes each day and for each node I am using around 30-40 Regex matches to see if they satisfy some conditions are not. These Regex...
4
by: Brian Henry | last post by:
I have phone numbers like this in a data table 123-435-1234 1231231234 432.234.2321 they all have different formatting, what I want to do is get them all formatted like this (123) 123-1234
5
by: Chris | last post by:
How Do I use the following auto-generated code from The Regulator? '------------------------------------------------------------------------------ ' <autogenerated> ' This code was generated...
4
by: ad | last post by:
I am useing VS2005 to develop wep application. I use a RegularExpress both in RegularExpressionValidator and Regex class to validate a value. The RegularExpress is 20|\-9|\-1|?\d{1} When I...
6
by: Rob | last post by:
I have built a class called DTLineScrub that inherits Regex. All works well with the code below until I try to do a replace on a string. It then tells me that the object was not instantiated. ...
4
by: Henrik Dahl | last post by:
Hello! In my application I have a need for using a regular expression now and then. Often the same regular expression must be used multiple times. For performance reasons I use the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.