Solved

Parsing part of a string, so that i only have the final segment

Posted on 2009-06-30
7
213 Views
Last Modified: 2012-05-07
I am attempting in C# to remove part of a name from a string.
Using the method Bellow i am able to get all of the data from a predefined directory and place it into a Checked List Box for the user to select.  My problem is that each line looks like this

C:\Users\von Houk\Documents\Test

i am trying to get it to appear in the box as just

Test

remove all of the directory information from the string.

string[] sPatientNames;

sPatientNames = System.IO.Directory.GetDirectories(dPatientData.Path);

clbPatientSelect.Items.AddRange(sPatientNames);

Open in new window

0
Comment
Question by:cotj73
  • 4
  • 3
7 Comments
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 total points
Comment Utility
Hi cotj73;

This will give you what you want.

clbPatientSelect.Items.AddRange(System.IO.Path.GetFileName(sPatientNames););  


Fernando
0
 
LVL 62

Assisted Solution

by:Fernando Soto
Fernando Soto earned 500 total points
Comment Utility
Sorry cotj73;

This is what you are looking for.

Fernando
string[] sPatientNames;

sPatientNames = System.IO.Directory.GetDirectories(dPatientData.Path);
 

for (int i = 0; i < sPatientNames.Length; i++)

{

    sPatientNames[i] = System.IO.Path.GetFileName(sPatientNames[i]);

}
 

clbPatientSelect.Items.AddRange(sPatientNames);

Open in new window

0
 
LVL 1

Author Comment

by:cotj73
Comment Utility
two questions
clbPatientSelect.Items.AddRange(System.IO.Path.GetFileName(sPatientNames););  

this line has two ; at the end separated by a )
is that supposed to be there it comes up as an error

and also it tells me that it can not be converted from type 'string[]' to 'string'

and the one last comment that is my fault for not saying is that i am pulling folder names, not files
in my program i was using
clbPatientSelect.Items.AddRange(System.IO.Path.GetDirectoryName(sPatientNames))'
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 1

Author Comment

by:cotj73
Comment Utility
sorry commented to late on that last comment, that is excatly what i need, except that it pulles a file name, from the directory selected i need the folder names, thank you for the help!
0
 
LVL 1

Author Comment

by:cotj73
Comment Utility
I figured it out




string[] sPatientNames;

sPatientNames = System.IO.Directory.GetDirectories(dPatientData.Path);
 

for (int i = 0; i < sPatientNames.Length; i++)

 {

   sPatientNames[i] = System.IO.Path.GetFileNameWithoutExtension(sPatientNames[i]);

 }
 
 

clbPatientSelect.Items.AddRange(sPatientNames);
 

Thank you so much for the Help

Open in new window

0
 
LVL 1

Author Closing Comment

by:cotj73
Comment Utility
Great Help, thank you so much sage for helping me on this problem
0
 
LVL 62

Expert Comment

by:Fernando Soto
Comment Utility
Very good, glad you got it working.  ;=)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

744 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

15 Experts available now in Live!

Get 1:1 Help Now