Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2009-06-30
7
Medium Priority
?
224 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
[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
  • 4
  • 3
7 Comments
 
LVL 64

Accepted Solution

by:
Fernando Soto earned 2000 total points
ID: 24748736
Hi cotj73;

This will give you what you want.

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


Fernando
0
 
LVL 64

Assisted Solution

by:Fernando Soto
Fernando Soto earned 2000 total points
ID: 24748833
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
ID: 24748837
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
Independent Software Vendors: 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 1

Author Comment

by:cotj73
ID: 24748879
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
ID: 24749037
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
ID: 31598489
Great Help, thank you so much sage for helping me on this problem
0
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 24749234
Very good, glad you got it working.  ;=)
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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

715 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