String Woes in VB.net

G

Guest

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
 
P

pvdg42

Gordon said:
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

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.
 
C

Curt

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top