472,780 Members | 1,544 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,780 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 3560
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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.