vb.net equivalent

J

John

Hi

What is the vb.net equivalent of;

y = Right(x, Len(x) - x.LastIndexOf("\"))

Thanks

Regards

PS: Trying to extract filename from the full path, in case anyone is
wondering.
 
F

Fergus Cooney

Hi John,

Now where have I see that idea? ;-))

sFileName = sFilePath.Substring (sFilePath.LastIndexOf ("\") + 1)

Regards,
Fergus

ps. You could have asked in the same thread - we'd have seen it!
 
J

Jay B. Harlow [MVP - Outlook]

John,
I would recommend the 'System.IO.Path.GetFileName' function that Herfried
pointed out in the other thread.

Hope this helps
Jay
 
T

Tom Shelton

Hi

What is the vb.net equivalent of;

y = Right(x, Len(x) - x.LastIndexOf("\"))

Thanks

Regards

PS: Trying to extract filename from the full path, in case anyone is
wondering.

Imports System.IO

....

Dim fileName As String = Path.GetFileName(pathToFile)

HTH
 
W

William Ryan

I agree with the approaches below and think they are preferable, but you cna
use Microsoft.VisualBasic.Right(...) if you need to .

HTH,

Bill
 
H

Herfried K. Wagner [MVP]

* "John said:
What is the vb.net equivalent of;

y = Right(x, Len(x) - x.LastIndexOf("\"))

You may want to use 'Strings.Right' to avoid problems.
 
H

Herfried K. Wagner [MVP]

* "Jay B. Harlow said:
I would recommend the 'System.IO.Path.GetFileName' function that Herfried
pointed out in the other thread.

Thanks...

;-)
 
F

Fergus Cooney

Hi Herfried, John,

Given that you know the starting point but not the number of characters:
Use Mid - save all the hassle with Len

Regards,
Fergus
 
C

Cor

Hi John,

I see everybody has to give you an answer

You can replace the fullpathname without the filename with "" if all other
things don't work Not that it is better, but again an alternative.

I never use that, but giving the same answer as the others is so easy.
:))
Cor
 
H

Herfried K. Wagner [MVP]

* "Fergus Cooney said:
Given that you know the starting point but not the number of characters:
Use Mid - save all the hassle with Len

I wouldn't use the string functions for splitting the path at
all... 'System.IO' is better.

;-)
 
H

Herfried K. Wagner [MVP]

* "Cor said:
I see everybody has to give you an answer
ROFL

You can replace the fullpathname without the filename with "" if all other
things don't work Not that it is better, but again an alternative.

I never use that, but giving the same answer as the others is so easy.

Still ROFL.
 
F

Fergus Cooney

Hi Herfried,

ROFL

I'm <sure> that's your name on the post that mentions Right()??

Regards,
Fergus
 
C

Cor

Hi Fergus,

He can go of from VB but never from his Right()s, with that I started a long
thread once with him. It was zero-zero, but that gave me the idea that you
could nice use your own favorites words in VB.

The same as in English the old Normandic or old Angel-Saxian words and
probably some Galic words.

:))

Cor
 

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

Similar Threads


Top