Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
|
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 6th, 2008, 05:24 AM
Authorized User
 
Join Date: Jul 2006
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default Trimming String

Hi there can anybody give me a codesnippet to trim to folling.

This is my result string:
C:\temp\MyAssembly.dll

But i only need:
C:\temp
The lenght of MyAssembly.dll is variable so i cant get te lenght of the string and cut it of. How do i get rid of the filename.

I hope you guys can help me.

Kind regards

MacDevv


 
Old May 6th, 2008, 05:48 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

There are a number of ways. You could use the FileInfo object and the Directory property but I think I'd use LastIndexOf(@"\") combined with Substring.

--

Joe (Microsoft MVP - XML)
 
Old May 6th, 2008, 06:10 AM
Authorized User
 
Join Date: Jul 2006
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your reply.

But can you give me a code snippet.

I dont get it/

 
Old May 6th, 2008, 06:36 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Sorry, but if you're not capable of looking up LastIndexOf and Substring then you're in the wrong field.

--

Joe (Microsoft MVP - XML)
 
Old May 6th, 2008, 08:10 AM
Authorized User
 
Join Date: Jul 2006
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks but no thank

Dissing members is not helping the community. If you are not willing to help starting programmer im wondering what you are doing here.

But i helped my self and this is how i solved the problem.

using System.IO;

private void LoadData()
{
    string fullPathAndFile = "c:\\temp\\text.txt";
    string fullPath = Path.GetDirectoryName(fullPathAndFile);
}

Kind regards,

MacDevv
 
Old May 6th, 2008, 08:55 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

I pointed out two methods, you found a third.

There's a difference between a willingness to help and doing the work for someone.

A search on Google for 'LastIndexOf C#' brings back a host of examples, some virtually identical to your problem. Why should I write yet another example because you couldn't be bothered to do a quick search once you'd been given a pointer?

I don't normally get annoyed but when you've answered over 2000 questions on a forum then you can start criticising others attitude.

--

Joe (Microsoft MVP - XML)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Trimming Words Nicky_uk Classic ASP Databases 5 February 21st, 2008 02:06 PM
Site map security trimming. weisma BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 5 December 25th, 2006 11:57 PM
Trimming a query for search arnabghosh Classic ASP Databases 1 May 31st, 2005 07:39 AM
how to replace a string with another string/number crmpicco Javascript How-To 4 March 14th, 2005 12:59 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.