Solved

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

Posted on 2013-05-21
9
490 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

635 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