Solved

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

Posted on 2013-05-21
9
479 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
Technology Partners: 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 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

749 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