Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2013-05-21
9
Medium Priority
?
494 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 75

Accepted Solution

by:
käµfm³d   👽 earned 1000 total points
ID: 39185736
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:Meir Rivkin
ID: 39185740
var str = String.Join("",System.IO.Path.GetFileNameWithoutExtension(rfiles).Skip(rfiles.Length-7).ToArray());
0
 
LVL 19

Expert Comment

by:Ken Butters
ID: 39185814
mystr = Right(System.IO.Path.GetFileNameWithoutExtension("c:\Users\test\Smith and Co Account.pdf"), 7)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 23

Expert Comment

by:Ioannis Paraskevopoulos
ID: 39186058
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
 
LVL 23

Assisted Solution

by:Ioannis Paraskevopoulos
Ioannis Paraskevopoulos earned 1000 total points
ID: 39186065
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 75

Expert Comment

by:käµfm³d 👽
ID: 39186422
@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
ID: 39186460
@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 75

Expert Comment

by:käµfm³d 👽
ID: 39187155
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
ID: 39188888
Thank you all.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

877 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