473,385 Members | 2,210 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,385 software developers and data experts.

String Woes in VB.net

Hi;

My goal is to remove the file name, minus the extension, from the following
string =
\\aServer\dir1\dir2\dir3\myfile.txt.

I tried all sorts of combinations of Instr() , revInstr() ex.

Dim hold as String = "\\aServer\dir1\dir2\dir3\myfile.txt."

Mid(hold, InstrRev("myFile.txt", "\"), Instr(1, "myFile.txt","." ))

This gets you close but is still a couple of characters off.

I even tried to hold.indexOf("\") and hold.LastindexOf("\") with and without
adding an offset of 1 and even these methods yielded a result that was a
couple of characters off.

SO what am I doing wrong ?

Thanks

--
Gordon
Aug 4 '06 #1
3 2406

"Gordon" <Go****@discussions.microsoft.comwrote in message
news:1D**********************************@microsof t.com...
Hi;

My goal is to remove the file name, minus the extension, from the
following
string =
\\aServer\dir1\dir2\dir3\myfile.txt.

I tried all sorts of combinations of Instr() , revInstr() ex.

Dim hold as String = "\\aServer\dir1\dir2\dir3\myfile.txt."

Mid(hold, InstrRev("myFile.txt", "\"), Instr(1, "myFile.txt","." ))

This gets you close but is still a couple of characters off.

I even tried to hold.indexOf("\") and hold.LastindexOf("\") with and
without
adding an offset of 1 and even these methods yielded a result that was a
couple of characters off.

SO what am I doing wrong ?

Thanks

--
Gordon
Have a look at the StringTokenizer class. Tokenize your string specifying
"\" as the delimiter, and specifying that delimiters be saved as tokens.
Remove the last token ("myfile.txt"), then reassemble the remaining tokens
into a string.
Aug 4 '06 #2
While this is good .. the Path class
http://msdn2.microsoft.com/en-US/lib...m.io.path.aspx already has
methods to break up a string representing a filename and would be much
easier to use.

My guess is that this would do exactly what he wanted
http://msdn2.microsoft.com/en-us/lib...extension.aspx

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung

"pvdg42" <pv****@newsgroups.nospamwrote in message
news:ua**************@TK2MSFTNGP03.phx.gbl...
>
"Gordon" <Go****@discussions.microsoft.comwrote in message
news:1D**********************************@microsof t.com...
>Hi;

My goal is to remove the file name, minus the extension, from the
following
string =
\\aServer\dir1\dir2\dir3\myfile.txt.

I tried all sorts of combinations of Instr() , revInstr() ex.

Dim hold as String = "\\aServer\dir1\dir2\dir3\myfile.txt."

Mid(hold, InstrRev("myFile.txt", "\"), Instr(1, "myFile.txt","." ))

This gets you close but is still a couple of characters off.

I even tried to hold.indexOf("\") and hold.LastindexOf("\") with and
without
adding an offset of 1 and even these methods yielded a result that was a
couple of characters off.

SO what am I doing wrong ?

Thanks

--
Gordon

Have a look at the StringTokenizer class. Tokenize your string specifying
"\" as the delimiter, and specifying that delimiters be saved as tokens.
Remove the last token ("myfile.txt"), then reassemble the remaining tokens
into a string.

Aug 4 '06 #3
One note, If you came from a VB6 background, Since 'C' starts string
offsets at 0 (Unlike VB6 did) , so does VB.NET.

Screw us VB programmers. We have been assimilated
We MUST Adapt to the 'C' way of life or die.

In article <1D**********************************@microsoft.co m>,
Go****@discussions.microsoft.com says...
Hi;

My goal is to remove the file name, minus the extension, from the following
string =
\\aServer\dir1\dir2\dir3\myfile.txt.

I tried all sorts of combinations of Instr() , revInstr() ex.

Dim hold as String = "\\aServer\dir1\dir2\dir3\myfile.txt."

Mid(hold, InstrRev("myFile.txt", "\"), Instr(1, "myFile.txt","." ))

This gets you close but is still a couple of characters off.

I even tried to hold.indexOf("\") and hold.LastindexOf("\") with and without
adding an offset of 1 and even these methods yielded a result that was a
couple of characters off.

SO what am I doing wrong ?

Thanks

Aug 5 '06 #4

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

Similar topics

7
by: Mark | last post by:
O, woe is me, to have seen what I have seen, see what I see! (That's Shakespeare for those who were wondering what I'm on about) I am "having fun" with cookies. And I wonder if I have...
0
by: Cedric | last post by:
This is a 3 weeks old problem, but having found a solution (and having looked for one here, finding only this message), I'm replying now. From: Jive (someone@microsoft.com) Subject: Upgrade...
3
by: Angel Cat | last post by:
Trying to get my jobs to send mail when job fails. Should be easy but it's giving me headache Had a whole slew of issues. Outlook is installed with a n outlook mail profile set up that can...
2
by: Andrew Thompson | last post by:
- NN 4.78 rendering woes, links at far left - I am trying to rework an old site, make it valid html and css, improving the x-browser and 'older browser' compatibility. My efforts so far, have...
0
by: Arun Bhalla | last post by:
I'm having some inconsistency problems with my deployment project ("Setup") and its custom actions ("Installer"). I'm using Visual Studio .NET 2003 (.NET 1.1, no service pack) on Windows XPSP1. ...
3
by: jcouse | last post by:
I am trying to find if a string exists in a file. If it doesn’t, it should return a “-1” and I’ll make my decision based on that Here is a sniplet of the text file game name mapp...
0
by: Caffiend | last post by:
Hello again! I am still having problems with the code under the title "newbie woes", but I have moved on for now to another exercise. The book has asked me to write a program that will use two...
9
by: Mark Rae | last post by:
Hi, This time, I'm looking for a regular expression which says "the string must contain exactly seven or exactly eight digits" e.g. 123456 fails 1234567 passes 12345678 passes 123456789...
3
by: bobdydd | last post by:
Hi Everybody I am trying to use string functions to extract data from a field called Me.txtDataRaw and put part of it into another field called Me.txtCurrent Me.txtDataRaw gets data as...
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:
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
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:
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...

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.