Solved

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

Posted on 2013-05-21
9
467 Views
Last Modified: 2013-05-22
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
0
Comment
Question by:nobushi
9 Comments
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 250 total points
Comment Utility
You could do the following:

Dim filename As String = System.IO.Path.GetFileNameWithoutExtension(rfiles)
Dim lastSeven As String = System.Text.RegularExpressions.Match(filename, ".{0, 7}$").Value

Open in new window


...where ".{0, 7}$" means between zero and seven ( {0, 7} ) of any character ( . ) that occurs at the end of the string ( $ ).
0
 
LVL 42

Expert Comment

by:sedgwick
Comment Utility
var str = String.Join("",System.IO.Path.GetFileNameWithoutExtension(rfiles).Skip(rfiles.Length-7).ToArray());
0
 
LVL 19

Expert Comment

by:Ken Butters
Comment Utility
mystr = Right(System.IO.Path.GetFileNameWithoutExtension("c:\Users\test\Smith and Co Account.pdf"), 7)
0
 
LVL 23

Expert Comment

by:Ioannis Paraskevopoulos
Comment Utility
Dim FileName As String = System.IO.Path.GetFileNameWithoutExtension("c:\Users\test\Smith and Co Account.pdf")

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

Giannis
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 23

Assisted Solution

by:Ioannis Paraskevopoulos
Ioannis Paraskevopoulos earned 250 total points
Comment Utility
Dim FileName As String = System.IO.Path.GetFileNameWithoutExtension("c:\Users\test\Smith and Co Account.pdf")

Dim Result = Array.Reverse(FileName.Split(" "))(0)

Giannis
0
 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
@jyparask

Neither of those give the last 7 characters; they both give the "word" following the last space in the filename.
0
 
LVL 23

Expert Comment

by:Ioannis Paraskevopoulos
Comment Utility
@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
0
 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
Not for me to say, but I wanted to clarify for anyone who "googles" this and does want 7 characters  : )
0
 
LVL 1

Author Closing Comment

by:nobushi
Comment Utility
Thank you all.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now