473,395 Members | 1,568 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,395 software developers and data experts.

Quick hack - getting the first word in the filename before the dot

We have a filename, which could theoretically be something like
verylongfilename.2004.05.11.txt. We just need the significant part before
the first dot. My solution was a quick regexp:

filename = (Regex.Split(filename, "."))[0];

Is there a better way to handle it? Maybe something built in?
--
Alex Moskalyuk
_____________________________
http://www.techinterviews.com
Nov 16 '05 #1
4 3578
Firstly you don't need regex... just filename.Split('.')[0] would suffice.
Secondly you could just use substring, as in...
filename = filename.Substring(0, filename.IndexOfAny('.')-1)

"Alex Moskalyuk" <us****@moskalyuk.com> wrote in message
news:OM*************@tk2msftngp13.phx.gbl...
We have a filename, which could theoretically be something like
verylongfilename.2004.05.11.txt. We just need the significant part before
the first dot. My solution was a quick regexp:

filename = (Regex.Split(filename, "."))[0];

Is there a better way to handle it? Maybe something built in?
--
Alex Moskalyuk
_____________________________
http://www.techinterviews.com

Nov 16 '05 #2
Thanks, using substring just escaped me.

--
Alex Moskalyuk
_____________________________
http://www.techinterviews.com
"John Wood" <sp**@isannoying.com> wrote in message
news:u8**************@TK2MSFTNGP09.phx.gbl...
Firstly you don't need regex... just filename.Split('.')[0] would suffice.
Secondly you could just use substring, as in...
filename = filename.Substring(0, filename.IndexOfAny('.')-1)

"Alex Moskalyuk" <us****@moskalyuk.com> wrote in message
news:OM*************@tk2msftngp13.phx.gbl...
We have a filename, which could theoretically be something like
verylongfilename.2004.05.11.txt. We just need the significant part before the first dot. My solution was a quick regexp:

filename = (Regex.Split(filename, "."))[0];

Is there a better way to handle it? Maybe something built in?
--
Alex Moskalyuk
_____________________________
http://www.techinterviews.com


Nov 16 '05 #3
John Wood wrote:
Firstly you don't need regex... just filename.Split('.')[0] would suffice.
Secondly you could just use substring, as in...
filename = filename.Substring(0, filename.IndexOfAny('.')-1)
Thirdly, you could make life *really* easy by using:

filename = System.IO.Path.GetFileNameWithoutExtension(filenam e);

;)

"Alex Moskalyuk" <us****@moskalyuk.com> wrote in message
news:OM*************@tk2msftngp13.phx.gbl...
We have a filename, which could theoretically be something like
verylongfilename.2004.05.11.txt. We just need the significant part before
the first dot. My solution was a quick regexp:

filename = (Regex.Split(filename, "."))[0];

Is there a better way to handle it? Maybe something built in?
--
Alex Moskalyuk
_____________________________
http://www.techinterviews.com


--

Ed Courtenay
[MCP, MCSD]
http://www.edcourtenay.co.uk
Nov 16 '05 #4
Ed Courtenay wrote:
John Wood wrote:
Firstly you don't need regex... just filename.Split('.')[0] would
suffice.
Secondly you could just use substring, as in...
filename = filename.Substring(0, filename.IndexOfAny('.')-1)

Thirdly, you could make life *really* easy by using:

filename = System.IO.Path.GetFileNameWithoutExtension(filenam e);

;)


Ignore me - I've just re-read the OP; I must remember to read posts more
thoroughly!

"Alex Moskalyuk" <us****@moskalyuk.com> wrote in message
news:OM*************@tk2msftngp13.phx.gbl...
We have a filename, which could theoretically be something like
verylongfilename.2004.05.11.txt. We just need the significant part
before
the first dot. My solution was a quick regexp:

filename = (Regex.Split(filename, "."))[0];

Is there a better way to handle it? Maybe something built in?
--
Alex Moskalyuk
_____________________________
http://www.techinterviews.com



--

Ed Courtenay
[MCP, MCSD]
http://www.edcourtenay.co.uk
Nov 16 '05 #5

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

Similar topics

0
by: Market Mutant | last post by:
on http://www.vbulletin.org/forum/showthread.php?s=&threadid=50116 it has http://www.vbulletin.org/forum/attachment.php?attachmentid=11156 but after i registered my account, I still can not...
12
by: Ron Weldy | last post by:
I have a test server runinng 2003/IIS 6 with a mixture of asp and asp.net files. On my workstation I have a share set up to the folder where the web files reside. I am just doing quick and dirty...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.