String Woes in VB.net

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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.
 
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.
 
Back
Top