Link to home
Create AccountLog in
Avatar of Kevin
KevinFlag for United States of America

asked on

VB.Net - Split string by last 5 characters of filename

Afternoon,

I am not sure how to use the split string to split a filename so that it writes the last 7 characters of the file name.

So for example my input would be "Smith and Co Account.pdf" and using the split string, output would be "Account"

Is someone able to help me finish this:

System.IO.Path.GetFileNameWithoutExtension(rfiles).Split

Open in new window



Please let me know if you have any question.

N
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
var str = String.Join("",System.IO.Path.GetFileNameWithoutExtension(rfiles).Skip(rfiles.Length-7).ToArray());
mystr = Right(System.IO.Path.GetFileNameWithoutExtension("c:\Users\test\Smith and Co Account.pdf"), 7)
Dim FileName As String = System.IO.Path.GetFileNameWithoutExtension("c:\Users\test\Smith and Co Account.pdf")

Dim Result = FileName.Split(" ")(UBound(FileName.Split(" ")))

Giannis
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
@jyparask

Neither of those give the last 7 characters; they both give the "word" following the last space in the filename.
@Kaufmed

You are very right, but i think this is the real requirement, as taking 7 last letters must be the example. If  the example was for instance "Smith and Co Acc.pdf" what sense would " Co Acc" make?

Giannis
Not for me to say, but I wanted to clarify for anyone who "googles" this and does want 7 characters  : )
Avatar of Kevin

ASKER

Thank you all.