473,591 Members | 2,872 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# - Split a path into a string[]

1 New Member
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 26619
prabunewindia
199 New Member
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
predsedateli
3 New Member
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
2763
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", "credits" or "license" for more information. >>> import os >>> file='/TEST/FILE.EXT'
12
5677
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
2848
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
4028
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 pathname component and head is everything leading up to that. The tail part will never contain a slash; if path ends in a slash, tail will be empty. If there is no slash in path, head will be empty. If
3
12369
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 part and a extension part. For example: '/Users/t/web/perl-python/I_Love_You.html' becomes
4
7561
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. -------------------------------------------------------------------------------- Compilation Error Description: An error occurred during the compilation of a resource
22
2916
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 = "/home/user/Documents/Textdocuments/Bills"; char **dirs; splitPath(path, dirs);
3
2466
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 many images stored as c:\mydatabse\images \images.jpg so computer A has no problem accessing the picture
3
1142
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 how can I do that. public static string ReadFileLines(string path) { int read = 0; StringBuilder builder = new StringBuilder(); byte buffer = new byte;
13
27950
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 return the whole sentence entact. import string from string import whitespace mytext = "The quick brown fox jumped over the lazy dog.\n" print mytext.split()
0
7935
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7871
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8236
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8227
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5735
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3851
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3893
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2379
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1467
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.