473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

C# - Split a path into a string[]

Hello,

I am working on a quick file browser project. i need to find a way to split a path:

(c:/somedir/somefile.txt)

into a string array:

[0] c
[1] somedir
[2] somefile.txt

is there any built in functionality to do this in c#? if not, does anybody know of any way that i can do this? Thank you very much for any help that you might be able to give, it will be much appreciated.

thanks, Andrew.
Apr 18 '07 #1
2 26549
prabunewindia
199 100+
hi friend,
plz try with this one

string a = "c:/somedir/somefile.txt";
string[] arr = a.Split('/');
and now u can get the separate strings as u like

prabu

I am working on a quick file browser project. i need to find a way to split a path:

(c:/somedir/somefile.txt)

into a string array:

[0] c
[1] somedir
[2] somefile.txt

is there any built in functionality to do this in c#? if not, does anybody know of any way that i can do this? Thank you very much for any help that you might be able to give, it will be much appreciated.

thanks, Andrew.[/quote]
Apr 18 '07 #2
hi!!
try this method:
add:
Expand|Select|Wrap|Line Numbers
  1. using System.Text.RegularExpressions;
  2.  
  3. string inputString = @"C:\somedir\somefile.txt";
  4. string[] parts = Regex.Split(inputString,@"\\");
  5.             foreach (string s in parts)
  6.             {
  7.                                     // process the strings
  8.            }
  9.  
:)

Hello,

I am working on a quick file browser project. i need to find a way to split a path:

(c:/somedir/somefile.txt)

into a string array:

[0] c
[1] somedir
[2] somefile.txt

is there any built in functionality to do this in c#? if not, does anybody know of any way that i can do this? Thank you very much for any help that you might be able to give, it will be much appreciated.

thanks, Andrew.
Apr 18 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Martijn Ras | last post by:
Heya folks, I ran into the following problem: When i run this on Windows everything is as expected: C:\>python Python 2.2.3 (#42, May 30 2003, 18:12:08) on win32 Type "help", "copyright",...
12
by: Martin Dieringer | last post by:
I am trying to split a file by a fixed string. The file is too large to just read it into a string and split this. I could probably use a lexer but there maybe anything more simple? thanks m.
1
by: porterboy76 | last post by:
QUESTION: How do I split a directory string into a list in Python, eg. '/foo/bar/beer/sex/cigarettes/drugs/alcohol/' becomes
12
by: Xah Lee | last post by:
Python Doc Problem Example Quote from: http://docs.python.org/lib/module-os.path.html ---------- split( path) Split the pathname path into a pair, (head, tail) where tail is the last...
3
by: Xah Lee | last post by:
Split File Fullpath Into Parts Xah Lee, 20051016 Often, we are given a file fullpath and we need to split it into the directory name and file name. The file name is often split into a core...
4
by: merrittr | last post by:
I have a string "c:\upload\file.txt" what I want is the file name to do this I was trying split on \ but I cant seem to get it to work? Server Error in '/appform' Application....
22
by: Sven-Thorsten Fahrbach | last post by:
Hi Does anybody know of a library that offers a function to split pathnames. It should work somewhat like the following code snippet: ----------------- char *path =...
3
by: najimou | last post by:
Hi everyone I will be having a split database, running on 2 computers via mapped drive. computer "A" will have one front end and the back end located in c: \mydatabse 2 tables have links to...
3
by: =?Utf-8?B?Ym9iYnk=?= | last post by:
I have the following code. bit it gives me error that The best overload method for string.Split(params char) has some invalid arguments. I am using stringbuilder which doesn't have split method so...
13
by: Chaim Krause | last post by:
I am unable to figure out why the first two statements work as I expect them to and the next two do not. Namely, the first two spit the sentence into its component words, while the latter two...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.