Solved

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

Posted on 2013-05-21
9
470 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 250 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:sedgwick
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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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 250 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

809 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